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.
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).
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.
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?
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.
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.
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
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.
@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.
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.
XSLT umbraco.item + replace
hi all,
im trying to do a replace within umbraco.item if that makes any sense.
so i've got..
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!
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
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.
Matt
hi guys,
thanks for the replies. the ReplaceLineBreaks is very handy! Matt, that doesnt work unfortunatley, get an XSLt error :(
Hey Felix
can you tell us what the xlst error is? Maybe try adding ?umbDebugShowTrace=true on the URL for some more details.
Matt
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.
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
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
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
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
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
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.
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.
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" />
@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
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?
or
Failing that I'll bow out ;)
Ooooh, good thinking batman, option 1 doesn't work, but 2 does if you change it to the following:
Pre 4.5
Post 4.5
Matt
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
Nice one, good work team! I've updated the docs here our.umbraco.org/wiki/reference/umbracolibrary/item
Awesome!
Thanks a bunch Matt and Peter!
is working on a reply...