I need to create a "text-only" version of an image-heavy umbraco site I've created. The only way I can think of at he moment is to "duplicate" all my templates into text only versions and then find a way to programatically change the template at run time based on a querystring value or session of "textonly".
The downside of this is that it means that every template I have created or will create in the future will need 2 versions - the normal version and the text-only version.
I did think about just having a seperate css but as 95% of images on the site are rendered in <img> tags, it will take much more than css-only changes I think.
Has anyone tried to do anything like this before? Is there a better way?
Hiding the image with CSS wont stop the image from downloading. The Image will still exist in the dom. The only fail safe way of having text only templates is to create alternate templates.
Then all you need to do is modify you nav to run in text only mode or something and append /text-page to end of the url which would give the page rendered in a text only way on a template called text-page.
Here's another "out there" alternative solution. Create a new base page class that inherits from "umbraco.UmbracoDefault" and override the Render() method. In there you can use some RegEx to remove all unwanted HTML from the HtmlTextWriter object, like <img> tags, etc.
Personally, I'd go with the alternative templates approach, it will give you greater flexibility in the end.
Do remember that you can take advantage of the 404handler "SearchForTemplate" ... so rather than using:
Thanks everyone for the replies - Hello Lee - just like old times!
I think its definitely going to have to be the alternative template approach - I think removing images on existing templates will screw the layout.
Regarding persisting the "text only" variable through the site - I'm currently doing that by using session variables in a user control in my master page. So I guess I just need to set a new "text only" variable (if the user clicks on the text only site link) and then interrogate this variable on every page and then somehow set the template programmatically? Is this possible I wonder?
This post helped me a lot today. Specifically, Lee Kelleher's suggestion about using a RegEx to remove markup when not wanted.
To give you a bit of background, I needed to produce HTML and plain-text output for a page (to be pulled into Campaign Monitor to become email content). To do this, I used the ?AltTemplate querystring parameter to switch to a different template and modified the render method in my new masterpage to strip out the HTML tags.
It ended up working really well. For anyone who's looking for some info on how to override the Render method, this helped me:
text only site
Hi,
I need to create a "text-only" version of an image-heavy umbraco site I've created. The only way I can think of at he moment is to "duplicate" all my templates into text only versions and then find a way to programatically change the template at run time based on a querystring value or session of "textonly".
The downside of this is that it means that every template I have created or will create in the future will need 2 versions - the normal version and the text-only version.
I did think about just having a seperate css but as 95% of images on the site are rendered in <img> tags, it will take much more than css-only changes I think.
Has anyone tried to do anything like this before? Is there a better way?
Thanks
Rich
I would be going down the css route.
img
{
visibilty: hidden;
display: none;
}
Hiding the image with CSS wont stop the image from downloading. The Image will still exist in the dom. The only fail safe way of having text only templates is to create alternate templates.
Then all you need to do is modify you nav to run in text only mode or something and append /text-page to end of the url which would give the page rendered in a text only way on a template called text-page.
Peter.
Why not just add a query, fx. www.site.com/?light=true, then in your templates test for that and don't render your images
Hello there Mr Rees!
Here's another "out there" alternative solution. Create a new base page class that inherits from "umbraco.UmbracoDefault" and override the Render() method. In there you can use some RegEx to remove all unwanted HTML from the HtmlTextWriter object, like <img> tags, etc.
Personally, I'd go with the alternative templates approach, it will give you greater flexibility in the end.
Do remember that you can take advantage of the 404handler "SearchForTemplate" ... so rather than using:
http://example.com/page.aspx?altTemplate=text
You can use:
http://example.com/page/text.aspx
Cheers, Lee.
Just thought of another solution. [I wish we could edit our forum posts]
You could add a UrlRewriting rule to rewrite pages with /text/ prefixed in the URL:
The only problem is how to persist the Text Only links through the navigation, which you could do via an XSLT extension?
Thanks everyone for the replies - Hello Lee - just like old times!
I think its definitely going to have to be the alternative template approach - I think removing images on existing templates will screw the layout.
Regarding persisting the "text only" variable through the site - I'm currently doing that by using session variables in a user control in my master page. So I guess I just need to set a new "text only" variable (if the user clicks on the text only site link) and then interrogate this variable on every page and then somehow set the template programmatically? Is this possible I wonder?
Richard, take a look at the following forum topics about using a HttpModule to handle dynamic MasterPages:
http://our.umbraco.org/forum/developers/api-questions/3687-dynamic-master-page
http://our.umbraco.org/forum/developers/api-questions/3732-IHttpModule-and-Umbraco
This post helped me a lot today. Specifically, Lee Kelleher's suggestion about using a RegEx to remove markup when not wanted.
To give you a bit of background, I needed to produce HTML and plain-text output for a page (to be pulled into Campaign Monitor to become email content). To do this, I used the ?AltTemplate querystring parameter to switch to a different template and modified the render method in my new masterpage to strip out the HTML tags.
It ended up working really well. For anyone who's looking for some info on how to override the Render method, this helped me:
http://www.west-wind.com/weblog/posts/2004/Jun/08/Capturing-Output-from-ASPNet-Pages
Cheers everyone!
is working on a reply...