Are you sure the link is not being outputted and just not being rendered because the href attribute might not get any value? What does your HTML source look like after this function has been run?
I don't understand why you're trying to do it this way. I just truncate the "body text" by itself, and then show the "read more" link independantly.
You could always set a variable that tells you if the body text is more than $MaxNoChars, and then test against that when choosing to truncate the text and display the link.
Do be careful with truncate string if that string has html/xml in it. You could end up truncating right in the middle of a tag. Imagine if your truncated text included "<b>blah" and missed the closing </b> tag.
To add the truncate text I'd probably use the concat() function or simply output it directly with
I actually wrote an xslt macro for an umbraco v3 site some time ago to trim some bodyText for use in showing blurbs next to links. Perhaps my approach would be an alternative to your?
The "BlurbText" macro contains the following. You'll notice that in my case I strip the html out of the text before trimming to length (hard-coded at 40 characters but this could be passed in as a variable). In my use I only wanted the actual text even if there were html markup in the item I was displaying.
umbraco.library: TruncateString
Is it possible to pass a variable containing html to the third variable in TruncateString? This is what I have:
<xsl:variable name="continueLink">
<a href="{umbraco.library:NiceUrl(@id)}">... read more...</a>
</xsl:variable>
<xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(data [@alias = 'bodyText']), $MaxNoChars, $continueLink) />
... but this is only outputting "... read more..." (no link).
I guess it should be possible.
Are you sure the link is not being outputted and just not being rendered because the href attribute might not get any value? What does your HTML source look like after this function has been run?
/Jan
It's just plain text. I did a test without the href like
<xsl:variable name="continueLink2">
<b>... read more...</b>
</xsl:variable>
... and the <b> tags are not output either.
Try to cast into a string like
I think the problem is that you have valid xml in the variable and it gives the xmlnode to the function
Thomas
Hmm... No luck with string($continueLink) I'm afraid. Should have said earlier I already tried that, sorry.
I also tried umbraco.library:HtmlEncode($continueLink)
... and umbraco.library:HtmlEncode(string($continueLink))
All giving same plain text result. Is this a bug do you think?
Rather than spend any more frustrating time on this, I think I will make a work-around such as:
if lengthOfPost > $MaxNoChars then
truncate post to MaxNoChars
concat the link
else
just display post
If anyone can get the thing to work like I wanted in the first place, or any other suggestions, I'd like to hear about it.
Cheers all!
Just remember that the TruncateString method includes the length of the 3rd param in the overall trimmed length.
i.e.
Yields:
I don't understand why you're trying to do it this way. I just truncate the "body text" by itself, and then show the "read more" link independantly.
You could always set a variable that tells you if the body text is more than $MaxNoChars, and then test against that when choosing to truncate the text and display the link.
You may need to escape your html, so it is not seen as a xml node:
Or try something like:
Do be careful with truncate string if that string has html/xml in it. You could end up truncating right in the middle of a tag. Imagine if your truncated text included "<b>blah" and missed the closing </b> tag.
To add the truncate text I'd probably use the concat() function or simply output it directly with
I actually wrote an xslt macro for an umbraco v3 site some time ago to trim some bodyText for use in showing blurbs next to links. Perhaps my approach would be an alternative to your?
My template code looked like:
The "BlurbText" macro contains the following. You'll notice that in my case I strip the html out of the text before trimming to length (hard-coded at 40 characters but this could be passed in as a variable). In my use I only wanted the actual text even if there were html markup in the item I was displaying.
Hope this helps or gives you some inspiration!
cheers,
doug.
Sorry, I mis-spoke... The "more" link was in the macro (not template as I said above) and it then called the helper template to get the blurb text.
cheers,
doug.
I'don't read whole discution, but if you need html output use xsl:copy-of instaed of xsl:value-of
is working on a reply...