As soon as i remove the output-escaping part, it all works like a charm, except my string is no longer truncated.
I tried setting the string through a variable first, but no luck. I don't know how a Truncate function is outputting additional <a> tags? I've triple checked that all my tags are close properly, which they are.
Has anyone tried something similar? I'm on the verge of going mental here ;-)
Well it's definitely not a bug. It makes sense that it just truncates text/html.
However I currently I can't wrap my head around the proper solution for what you're trying to do. I'll let you know if an idea pops up all of the sudden.
Out of pure interest and lack of knowledge of the truncate function:
How is it not a bug that a for each loop causes multiple outputs of half-broken a tags when disable-output-escaping="yes" is added to a truncate functionality?
I'm using this snippet on another site, where there's no problems, also in a for-each loop:
Even if i disable the javascript creating the slide effect, it still happens. It's quite a mindboggle that i have it working on one site, but not the other.
I'm not refering to the function itself being a bug. My problem is that using truncate in this case breaks the html structure when i add disable-output-escaping="yes"
It seems like the for-each loop returns more nodes than there are, as soon as i add the above to the value-of string.
Visuals:
When i remove disable-output-escaping="yes", these a tags disappear and everything works like intended:
I'm not interested in plain text as i need the paragraphs for the formatting of the text.
The issue at hand is that you would like to truncate the content, and keep the HTML intact, right? As you know the TruncateString method is only going to truncate a string - it doesn't care whether it's plain-text, HTML or C# code, it's going to cut off the string once it reached the specified number of characters.
(The screengrabs you posted are from the browser's rendered view - guessing it's from Chrome, but could be Firefox's Firebug ... essentially what you see isn't a true representation of the HTML output, it's the web-browser's interpretation of the HTML, e.g. it will try to auto-correct mistakes)
The answer to your original problem is to use a method that is going to keep the HTML intact. Luckily, the guys at CogWorks wrote a blog post about this very thing a while back. Take a read over the post, hopefully it will help. (ignore the fact it uses Blog4Umbraco) http://thecogworks.co.uk/blog/2011/1/21/n-word-preview-for-blog4umbraco
TruncateString breaks html (bug?)
Hi
I use TruncateString to limit the number of characters in a teaster text, in a slider gallery (image + text).
When "disable-output-escaping="yes" is in the code, my page will literally fall apart with weird half-cut <a> tags that surround
like:
<a class="ui...<p class=" infobtncontainer"="" href="#">
As soon as i remove the output-escaping part, it all works like a charm, except my string is no longer truncated.
I tried setting the string through a variable first, but no luck. I don't know how a Truncate function is outputting additional <a> tags? I've triple checked that all my tags are close properly, which they are.
Has anyone tried something similar? I'm on the verge of going mental here ;-)
Hi Martin
What type of property is your teaser text? Is it a RTE or a multiple text box?
/Jan
* That surround my main divs thus making all text below my slider a link to '#'.
Hi Jan
Oh sorry, it's RTE
Hi Martin
Ok, then you should probably use the umbraco.library:StripHtml extension like...
umbraco.library:Truncate(umbraco.library:StripHtml(teaerText),number(100)).
Hope this helps :)
/Jan
Hi Jan
I thought about that,but the teasertext has paragraphs, so i would very much like to output the
tags from the RTE so the 209 character long teaser is nicely output with 2x 3-4 line paragraphs.
Also, inserting the <p> tags manually is not an option for my client.
To clarify;
This is how i want it to look, so the <p> tags need to be there, but not shown, hence disable-output-escaping should be there:
xslt code:
Hi Martin
Well it's definitely not a bug. It makes sense that it just truncates text/html.
However I currently I can't wrap my head around the proper solution for what you're trying to do. I'll let you know if an idea pops up all of the sudden.
/Jan
Hi Jan
Out of pure interest and lack of knowledge of the truncate function:
How is it not a bug that a for each loop causes multiple outputs of half-broken a tags when disable-output-escaping="yes" is added to a truncate functionality?
I'm using this snippet on another site, where there's no problems, also in a for-each loop:
Even if i disable the javascript creating the slide effect, it still happens. It's quite a mindboggle that i have it working on one site, but not the other.
Hi Martin,
The Truncate function is not a bug, if you only want plain text from the xslt try this
//fuji
Hi Fuji
I'm not refering to the function itself being a bug. My problem is that using truncate in this case breaks the html structure when i add disable-output-escaping="yes"
It seems like the for-each loop returns more nodes than there are, as soon as i add the above to the value-of string.
Visuals:
When i remove disable-output-escaping="yes", these a tags disappear and everything works like intended:
I'm not interested in plain text as i need the paragraphs for the formatting of the text.
Hi Martin,
The issue at hand is that you would like to truncate the content, and keep the HTML intact, right? As you know the TruncateString method is only going to truncate a string - it doesn't care whether it's plain-text, HTML or C# code, it's going to cut off the string once it reached the specified number of characters.
(The screengrabs you posted are from the browser's rendered view - guessing it's from Chrome, but could be Firefox's Firebug ... essentially what you see isn't a true representation of the HTML output, it's the web-browser's interpretation of the HTML, e.g. it will try to auto-correct mistakes)
The answer to your original problem is to use a method that is going to keep the HTML intact. Luckily, the guys at CogWorks wrote a blog post about this very thing a while back. Take a read over the post, hopefully it will help. (ignore the fact it uses Blog4Umbraco) http://thecogworks.co.uk/blog/2011/1/21/n-word-preview-for-blog4umbraco
Good luck!
Cheers, Lee.
Hi Lee
Adding more characters to the truncate function indeed does fix the issue, how sad i didn't figure that part out by myself.
Anyway, thank you very much for pointing out the obvious and thanks a bunch for the reference!
I think both Jan and Fuji tried to say the same i just didn't get it.
Thank you all for helping out!
Hi Martin,
Glad that you've found a fix. No worries about things appearing 'obvious' - we are all here to help and learn. :-)
Cheers, Lee.
Indeed the friendliest community on the planet!
is working on a reply...