Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Jul 05, 2014 @ 11:32
    Paul Griffiths
    0

    Xslt to ignore new line in RTE

    Hey all,

    I have a Rich text editor which has the alias bodyText and using the following systax <p><xsl:value-of select="umbraco.library:TruncateString(./bodyText, 300,'')" disable-output-escaping="yes" /><xsl:text>... </xsl:text> <a class="read-more" href="{umbraco.library:NiceUrl(@id)}" title="read more">read more</a></p>it is pulling 300 characters from the property and displaying it as a snippet text in a list of items.

    I was wondering if there was a way in xslt to ignore any new line that is made in the RTE.

    I want my list item to look like this

    enter image description here

    but if the content editor decide to begin a new line it runs the risk of looking like this

    enter image description here

    The only other way i thought of doing it is creating a new property called teaser text (simple editor) and using uComponents to set a char limit. but i was thinking that the content editor may have to enter the same info twice.

    Any help would be great thanks

    Paul

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jul 05, 2014 @ 12:08
    Dennis Aaen
    101

    Hi Paul,

    Maybe you could use the library method called umbraco.library:Replace, you can find some documentation about the library method here: http://our.umbraco.org/wiki/reference/umbracolibrary/replace

    <xsl:variable name="text" select="umbraco.library:TruncateString(./bodyText, 300,'...')" />
    <xsl:variable name="cleanText" select="umbraco.library:Replace($text, '&#xA;', '')"/>

    <xsl:value-of select="$cleanText" />
    <a class="read-more" href="{umbraco.library:NiceUrl(@id)}" title="read more">read more</a>

     

     

    For the replace part I found inspiration here: http://our.umbraco.org/forum/developers/xslt/9239-Removing-TinyMCE-line-breaks

    Hope this helps or can lead you in the right direction,

    /Deenis

  • Paul Griffiths 370 posts 1021 karma points
    Jul 05, 2014 @ 12:45
    Paul Griffiths
    0

    Hey Dennis thanks for the prompt reply :).

    I will use your information as a base to solve the problem in question.

    Thanks a lot mate

    Paul

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jul 05, 2014 @ 13:35
    Dennis Aaen
    0

    Hi Paul,

    Good to hear Paul, I think that maybe you can use the code that I provide you, in the previous post.

    If it the case, then remember to mark the questions as solved.

    /Dennis

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jul 06, 2014 @ 19:13
    Chriztian Steinmeier
    1

    Hi Paul,

    You should be very careful when using string manipulation on the contents of the RTE - remember that it's HTML, so you could very easily end up truncating in the middle of en <em> tag or a link, which could render the rest of the page unusable...

    For the newlines, in this case, you could also just use CSS - if you wrap the output in a

    and define some rules, e.g.:

    .description p, .description br { display: inline; }
    

    /Chriztian

  • Paul Griffiths 370 posts 1021 karma points
    Jul 06, 2014 @ 20:27
    Paul Griffiths
    0

    Hi Chriztian,

    Good point mate I will take that into consideration :) I think the CSS is a good call.

    Thanks for the advice mate

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft