Copied to clipboard

Flag this post as spam?

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


  • Felix 46 posts 67 karma points
    Jul 05, 2010 @ 05:57
    Felix
    0

    XSLT umbraco.item + replace

    hi all,

    im trying to do a replace within umbraco.item if that makes any sense.

    so i've got..

    <xsl:value-of select="umbraco.library:Item($currentPage/@id, 'headerText')" />

    headerText is a multi line text area for me . I want to replace the value of line breaks with BR's. However  i cant seem to be able to get a replace in there while still maintianing the ability to edit that item in canvas mode.

    thanks in advance!

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 05, 2010 @ 09:04
    Kim Andersen
    0

    Hi Felix.

    This is not the final solution to your problem and I'm not sure how this will work, as I'm not totally certain how the Item-extension wil react. But when you are going to make the replace-function, you can probably use the ReplaceLineBreaks-extension: umbraco.library:ReplaceLineBreaks

    This will replace text line breaks with HTML line breaks (br-tags).

    /Kim A

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 05, 2010 @ 09:43
    Matt Brailsford
    0

    I'm not entirley sure, as I've not used canvas editing, but it seems as though you can pass in a third parameter to format the output, so maybe something along these lines would work.

    <xsl:value-of select="umbraco.library:Item($currentPage/@id,'headerText',umbraco.library:ReplaceLineBreaks({0}))" disable-output-escaping="yes" />

    Matt

  • Felix 46 posts 67 karma points
    Jul 07, 2010 @ 02:50
    Felix
    0

    hi guys,

    thanks for the replies. the ReplaceLineBreaks is very handy! Matt, that doesnt work unfortunatley, get an XSLt error :(

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 07, 2010 @ 08:19
    Matt Brailsford
    0

    Hey Felix

    can you tell us what the xlst error is? Maybe try adding ?umbDebugShowTrace=true on the URL for some more details.

    Matt

  • Felix 46 posts 67 karma points
    Jul 08, 2010 @ 02:36
    Felix
    0

    hi Matt,

    here is the relevant bit when i put the DebugTrace into the URL :

    Error loading XSLT testing.xslt
    Unexpected token '{' in the expression.
    ...braco.library:ReplaceLineBreaks( -->{<-- 0}))
      at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
      at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
      at umbraco.macro.CreateXsltTransform(XmlTextReader xslReader, Boolean debugMode) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\presentation\macro.cs:line 620
      at umbraco.macro.getXslt(String XsltFile) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\presentation\macro.cs:line 600
      at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\presentation\macro.cs:line 677


    Its to do with the {0} , Visual Studio also says Unexpected Token '{' in expression.

    Cheers.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 08, 2010 @ 09:34
    Matt Brailsford
    0

    Hey Felix,

    Could you try the following and see if this works (I've wrapped the ReplaceLineBreaks in single quotes):

     <xsl:value-of select="umbraco.library:Item($currentPage/@id,'headerText','umbraco.library:ReplaceLineBreaks({0})')" disable-output-escaping="yes" />

    If this doesn't work, another one to try, would be to change {0} to {{0}}, as internally, that third param gets passed through a string.format statement, so this should escape it.

    If you give these a try and let me know how you get on?

    Matt

  • Felix 46 posts 67 karma points
    Jul 12, 2010 @ 03:48
    Felix
    0

    hi Matt,

    Thanks again for your efforts. Unfortunatley putting it within single quotes just makes it output 

    umbraco.library:ReplaceLineBreaks({0})

    on the page. i also tried putting in two {{'s but that again gives the same original XSLT error.

     

    Cheers

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 12, 2010 @ 16:54
    Matt Brailsford
    0

    K, could you try with 3 '{' characters, it actually looks like it goes through 2 string.formats before it gets to the bit you actualy need the token for.

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 12, 2010 @ 22:41
    Matt Brailsford
    0

    Hmmm, I've actualy setup a demo of this now, and looking into it, I'm not sure you are going to be able to make it work using the third parameter. For some reason, in the umbraco code, it wraps anything you do in comas, so effectivley it's assuming it's always a string, which seems a little pointless to me, but then I don't really know that much about it. That being said, unless anybody else can prove me wrong, I think you may be out of luck.

    Anybody?

    Matt

  • Felix 46 posts 67 karma points
    Jul 13, 2010 @ 04:57
    Felix
    0

    hi Matt,

    thanks a lot for your efforts, temporarily i just use a rich text editor with no formatting capabilities so the br's dont cause an issue and this way they can edit the content in canvas. But it would be beniftial if we got a working solution with text areas as im sure others have/will experienced this problem too

    Cheers

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 13, 2010 @ 09:41
    Matt Brailsford
    0

    Hi Felix,

    I managed to get something sort of working, but couldn't get canvas editing working. Maybe you'd like to give it a try.

    Basically, the umbraco.library:Item just outputs a string in a specific format, so if we just replicate the string, it seems to work (apart from the issue i'm having). Give this a try and see how you get on.

    <xsl:value-of select="concat('[[[ [umbraco:Item nodeId=&quot;', $currentPage/@id, '&quot; field=&quot;headerText&quot; xslt=&quot;umbraco.library:ReplaceLineBreaks({0})&quot; xsltdisableescaping=&quot;true&quot;] ]]]')" disable-output-escaping="yes" />

     

     

    Matt

    PS There should be no spaces in the for square brackets, I just had to put them in to stop the forum from stripping out my code.

     

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jul 13, 2010 @ 12:35
    Peter Duncanson
    0

    Going at this one a bit heavy handed ain't we ;)

    Why not just do this or am I missing something?

    <xsl:variable name="textWithBrs" select="umbraco.library:Item($currentPage/@id, 'headerText')" />
    <xsl:variable name="textMinusBrs" select="umbraco.library:ReplaceLineBreaks( $textWithBrs )" />
    <xsl:value-of select="$textMinusBrs" />
  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 13, 2010 @ 12:39
    Matt Brailsford
    0

    @pete - the issue is trying to get the property defined in XSLT to be editable in Canvas edit mode, which requires you to use the umbraco:item control.

    Matt

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jul 13, 2010 @ 12:57
    Peter Duncanson
    0

    Ok ain't got a test of this set up but from the docs () it seems to be saying you can apply some XSL in the third param which you are trying but you are doing a C# string replace so guessing you've been poking around in the source.

    Can't you do something like this though?

    <xsl:value-of select="umbraco.library:Item($currentPage/@id,'headerText',umbraco.library:ReplaceLineBreaks(.))" disable-output-escaping="yes" />
    

    or

    <xsl:variable name="myText" select="umbraco.library:ReplaceLineBreaks( $currentPage/@id )" />
    <xsl:value-of select="umbraco.library:Item($currentPage/@id,'headerText', $myText )" disable-output-escaping="yes" />
    

    Failing that I'll bow out ;)

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 13, 2010 @ 13:07
    Matt Brailsford
    1

    Ooooh, good thinking batman, option 1 doesn't work, but 2 does if you change it to the following:

    Pre 4.5

    <xsl:variable name="myText" select="umbraco.library:ReplaceLineBreaks($currentPage/data[@alias='headerText'])" />
    <xsl:value-of select="umbraco.library:Item($currentPage/@id,'headerText', $myText)" disable-output-escaping="yes" />

    Post 4.5

    <xsl:variable name="myText" select="umbraco.library:ReplaceLineBreaks($currentPage/headerText)" />
    <xsl:value-of select="umbraco.library:Item($currentPage/@id,'headerText', $myText)" disable-output-escaping="yes" />

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 13, 2010 @ 13:10
    Matt Brailsford
    0

    The trick then seems to be you need to do your formatting before hand and then just pass it in as the third param.

    Matt

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jul 13, 2010 @ 13:56
    Peter Duncanson
    0

    Nice one, good work team! I've updated the docs here our.umbraco.org/wiki/reference/umbracolibrary/item

  • Felix 46 posts 67 karma points
    Jul 14, 2010 @ 03:25
    Felix
    0

    Awesome!

    Thanks a bunch Matt and Peter!

Please Sign in or register to post replies

Write your reply to:

Draft