Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • syn-rg 282 posts 425 karma points
    Mar 08, 2011 @ 01:29
    syn-rg
    0

    Truncate HTML to finish at the end of a word.

    I believe this can be done, but can't find anything to work for me.

    I want my truncated HTML to finish at the end of a word instead of halfway into a word. I think it would work by first calculating the number of characters, then finishing at a space " " instead of the last character.

    <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(./mainContent), 40,'...')" />

    So in the above example it would display the first 40 HTML characters from mainContent, and finish on a space, or before a comma, period, hyphen or any other nominated characters.

    So instead of :
    We will build the new $13m Sport, Rec... (40 characters)

    It would be:
    We will build the new $13m Sport... (35 characters)

    Has anyone got a solution to this?

    Cheers,
    JV

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 08, 2011 @ 03:27
    Lee Kelleher
    2

    Hi JV,

    There is an XSLT extension called "GetFirstWords" in uComponents.

    http://ucomponents.codeplex.com/wikipage?title=Strings

    You can select the number of words to use, and the appender string at the end - which defaults to "..."

    ucomponents.strings:GetFirstWords(string text, int count, string appender)

    This function doesn't strip any HTML, so remember to call "umbraco.library:StripHtml" first.

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft