How to alter the prefixes EPiServer is adding to src attributes in html - episerver

I have a fragment of html which is contained in a property of a templated EPiServer page, within that html there is an img tag which has a relative url in it.
When the page is viewed, I can see the src attribute of the tag has been altered to have the prefix /ProjectName/Templates/Pages/.
I understand that this is being done by HtmlRewriteToExternal so that image files that are stored alongside the aspx template (which does indeed live in Templates\Pages) are located correctly, however the image which is intended to be part of the html fragment is in my case actually stored under PageFiles/nnn/ (where nnn is actually the parent page's PageFolderID), and I need to somehow make the altered html reflect that.
I've created a class that inherits from FriendlyUrlRewriteProvider and registered my class. I can debug the application, and watch the requests go through the overridden methods, but I still can't see where the prefix is being added or get any idea how to change it. I can alter the src tag to a different relative path in my class, but the prefix is still being added.
I've read everything I can find on the EPiServer url rewriting, but can't find anything that hints as to where this prefix is being added or how to stop that or change it.
Things I've read:
http://blogs.interakting.co.uk/post/File-Extensions-and-URL-Rewriting-in-EPiServer.aspx
http://blog.fredrikhaglund.se/blog/2008/05/07/disable-episerver-urlrewriter-interference/ (this may contain the answer I'm looking for)
http://labs.kaliko.com/2010/11/prevent-episerver-urlrewrite.html
http://sourcecodebean.com/archives/episerver-friendly-urls-for-paginated-pages-and-why-the-asplinkbutton-must-die/510
http://tedgustaf.com/en/blog/2008/7/create-a-custom-url-rewrite-provider-for-episerver/
http://tedgustaf.com/en/blog/2011/4/publishing-plain-html-pages-in-episerver/
http://sdk.episerver.com/library/cms5/Developers%20Guide/Friendly%20URL.htm
http://sdk.episerver.com/library/cms6.1/html/T_EPiServer_Web_UrlRewriteModule.htm
http://labs.episerver.com/en/Blogs/Ruwen/Dates/111218/112064/112154/
http://world.episerver.com/Blogs/Magnus-Strale/Dates/2011/3/Do-we-really-need-yet-another-HTML-parser/
http://world.episerver.com/Blogs/Yugeen-Klimenko/Dates/2011/6/How-EPiServer-URL-Rewriting-works/
http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=46869
I'm open to completely different solutions for what I'm actually trying to achieve, which is as follows:
I have multiple independent sets of static html files and related image / css / js files, which I'm trying to store / publish with EPiServer. The structure of each set looks something like
setfolder/
htmlfileA.html
htmlfileB.html
css/
styles.css
images/
piccy1.png
piccy2.png
js/
magic.js
I've figured that I should create an EPiServer page for the set, and then child pages for each html file, storing the html from the files in a property of the child pages. Currently I'm storing the related static files in the PageFiles of the relevant setfolder page, as that seems to be the most logically consistent place to put them.

It's hard to give the best solution without seeing it all infront of you. But one easy way is to alter the HTML-code when you print the property to the page.
Like <%= ChangeRelativeLinks(CurrentPage["HtmlCode"] as string) %>
And in the ChangeRelativeLinks(string htmlCode) you do a regexp or similar that changes relative links and images to the pagedir as an absolute path.

If you are storing the images in PageFiles which is a Virtual Path Provider you should be able to get the url to your file simply by using the API. On the PageData class (ie CurrentPage in your template) you have a method called GetPageDirectory() which gets the page folder.
You can read more about VPP concepts here:
http://sdk.episerver.com/library/cms6.1/Developers%20Guide/Core%20Features/File%20System/File%20System%20and%20VPPs.htm
No need for a url rewrite provider for this I think.

Related

How to use the same layout in a different directory?

I have a site using the hugo-coder theme, which has a layouts/posts folder that specifies that anything in the "posts" folder will have a blog post format.
I would like to have two different blogs in two different subdirectories, using the same layout. Is there a way to tell Hugo that the content/blog1 directory should use the same settings and layout as the content/posts directory without copying themes/hugo-coder/layouts/posts into layouts/blog1? Ideally I would avoid using symlinks, because, while convenient, I've had a decent amount of software throw weird errors when I use symlinks, so I avoid them when it's possible.
You can set the layout or type field to posts in the frontmatter of your _index.md file in content/blog1.
See this docs page for more info.
Edit: Alternatively, you could create an archetype for blog1 that automatically sets the value to posts in the frontmatter of individual posts in that section, assuming you're using hugo new blog1/postname.md to create posts for that section.
Double edit: The first suggestion didn't work. You could also create subsections within content/posts/blog1 and set the permalinks of posts in that subsection to use the last section only. That should remove the need to explicitly set the type in post frontmatter every time because each post would already have a type of posts.
In config.toml:
[permalinks]
posts = "/:sections[last]/:slug/"
You can use a partial in your templates. If you do that you WILL need the single and list file in the layouts/blog directory, but it could be an empty file referencing the partial. The layouts/posts/single.html and the layouts/blog/single.html both will then look like this:
{{ partial "singleblog.html" . }}
Compeletely DRY... and without much complexity.

Redmine: How to link an attached file in a project from its underprojects?

Lets say I have Project A with an attached imageFile.
Then I created 10 different Projects which are underprojects of Project A.
I want to link the ImageFile of Project A to the Wiki of every underproject , so that I can see the ImageFile in the Wiki-Area of each underproject.
What im doing so far is to copy full path of the attached file of Project A in the Wiki of every underproject, like for example:
!>/attachments/download/157/schnittprofil.png!
Is there a better way to achieve that, because every time I update the imagefile, I have to renew the id-numbers of all imagefile-links in the underprojects.
Since an attachment is only actually identified by its ID and all attachments are immutable (i.e. can be changed after upload), new uploads will result in a new ID. Since multiple attachments with different IDs can have the same name, you can also not reliably find an attachment just by using its name in broad contexts.
That said, to solve your issue, you could use the include macro to include a common Wiki page in your sub-project's wiki pages which then displays the image attachment.
For that, you can create a Wiki page named e.g. Schnittprofil in your parent project where you directly upload your file. In the wiki page, just reference the image with
!schnittprofil.png!
Assuming the parent project has an identifier of project-a, you can then include the page in other wiki pages with
{{include(project-a:Schnittprofil)}}
Each time you change the page on the parent project, it will automatically also show the updated content on the child wikis. The only requirement is that the users need to be able to read the wiki of your parent project (e.g. are members of the project with the "Read wiki" permission).

cakephp Managing Plugin Views how to determine paths

I have a plugin installed that has its own layout overrides for different controllers. However I'm having trouble understanding the mechanism for modifying the paths.
In the plug-in controller if I tell it to use my layout
$this->layout = 'default_dashboard';
Which is in app/Views/Layout and references an image in app/webroot/default_images.
All the relative links work fine to default_images when I do this, but would like to use some of the Plugin template overides for other actions.
However if I modify the default.cpt file to include some of the images, like say a logo that is used in default_dashboard.ctp. It is unable to map to the same image location.
For example in default.ctp:
echo $this->Html->image('default_images/logo.png',array('alt' =>
'Logo','width'=>'284','height'=>'82'));
produces a path to /img/default_images/logo.png. The Plugin is configured to use the /img location, whereas I want to direct to /default_images in this case. I could make this ../default_images/logo.png, but this isn't very clean.
In addition I have js and css which is having a similar problem. Can someone please explain the mechanism for using a site-wide default.ctp so that it works with inherited plugin templates?
From hard coding the links into the template not using the Html Helper, I see that the browser's relative path is confused because of the routing. For example the first one works with the root specified, the second doesn't.
<img src="/default_images/logo.png" alt="works" width='284' height='82'>
<img src="default_images/logo.png" alt="lost" width='284' height='82'>
What's the best way to make sure that the Plugin layouts and non-plugin layouts can all find the correct path to /default_images ?
Following are the steps that you can follow to resolve relative path problem:
Create a file abc_constants.php in app\Config folder.
Include the file in app\Config\bootstrap.php
require_once(abc_constants.php);
abc_constants.php should contain:
define('HTTP_HOST', "http://" . $_SERVER['HTTP_HOST'].'/');
define('SITE_URL', HTTP_HOST.'your_app_name/');
define('IMAGE_HTTP_PATH', SITE_URL.'app/webroot/default_images/');
Use these constants in your view file accordingly.
<?php echo $this->Html->image(IMAGE_HTTP_PATH.'logo.png',array('alt' => 'Logo','width'=>'284','height'=>'82'));
It looks a bit lengthy process at first time, but once implemented, you can use these constants in Ajax calls in view files, controller's code etc.

Drupal 7 Template Suggestions not working

If I create a region in the info file like:
regions[footer_panel] = Footer panel
then render this in the page template (page.tpl.php):
print render($page['footer_panel']);
then try and create an overide template to work with (as described in documentation):
block--footer_panel.tpl.php
finally print some static text in that file, Im not getting any results. Please could someone advise?
Caches have been flushed and block.tpl is in the templates folder.
Try adding the generic block.tpl.php to the theme as well. Sometimes it won't pick up the block template suggestions if that file isn't present first. Be sure to clear the cache again.
I'm also assuming that you have a block inserted into that region. If you do not have a block designated to show in that region creating a template file will do nothing. You need to create a block and then create the template file based on that blocks name/ID not the region name.

Drupal Attachments (FileField) file path

What function in Drupal gets file attachment path?
Edit: the attachments provided by Upload module in system section. But since you mentioned there may be another way around it. Maybe I could achieve may goals using FileField module so if you could tell me how to get a direct link of a file uploaded by FileField module that may also be very helpful.
Edit 2:
Ok I will start from my main and final objective:
It is to get an image linking to a file which visibility I could be managed using CCK module.
I am doing this step by step. So now I have written a code which generates the needed image and I have added that image to one of content types teaser. I found a way to warp my image in a tag and I had dug up simple attachments url. So my next step is to advance from simple upload attachment to the one added by FileFields and from odd looking HTML pace in all PHP document into beautifully managed CCK field.
How to fetch file path of a file uploaded FileFields?
Some plain and at the same time rich tutorials for making custom fields for CCK module.
Assuming you know how to get the $node object for a node containing a file attachment, this is super easy:
Upload (core)
$file = upload_load($node);
echo $file[1]->filepath;
Where 1 is the index of the file. Upload can let you upload more than one file, so file 2 would have an index of 2 and so on. If there's only one file, it'll always be 1.
More info: upload_load() API reference.
FileField
echo $node->field_fieldname[0]['filepath'];
Where field_filename is the short name you've used for the field, and 0 is the index of the field. CCK fields let you have multiple values in one field, so 0 would be the first, 1 would be the second, etc. If you only have one value, it'll always be 0.
Note: if you want to get the rendered output of the FileField using its formatters, you can just use $field_fieldname in your node template, or if you want to store the rendered output, you can use:
echo content_format('field_fieldname', $node->field_fieldname[0]);
More info: content_format() API reference.
Upload is a sad little module, and has been completely replaced with a core implementation of FileField in Drupal 7. If you have the option to use FileField, you should.
Don't direct links of file attachments appear below the uploaded file for the core Upload module?
Since you are trying to use images, you should use http://drupal.org/project/imagefield CCK module in order to add images to specified content type. After that using the Display fields tab in Content type configuration you can specify how image would be presented (as a link, image, image with link to node...) both in teaser and body view.

Resources