I've added an umbraco:Item control to render some text to the page. I want to replace newlines with <br> tags, however the built in convertLineBreaks method always returns <br/>. The problem is, I'm using the HTML 4.01 strict docytype so need it to output <br> in order the validate. Anyone know how to change it's output?
I haven't used html (rather than xhtml) in years so I haven't tried this to be sure, but I think that if you used an xslt macro you could get the effect you want.
Shout if you need more details of the steps, but here is the basic idea...
Create a new xslt macro and use the 'clean' template. Then add some xsl:value-of statements for the fields you want to display (more on this in a moment). In your template where you now have the umbraco:Item, delete that line and replace it with a call to your macro instead. The macro will create the output and place that output into your template just as the umbraco:Item had done.
Now, the key with your xslt macro is that you A) want to convert the linebreaks, and B) want the output to be in html-compliant format, not xhtml. The first step is easy as there's a built-in library function (umbraco.library:ReplaceLineBreaks()), and the second is easy because you can specify the output format of your xslt in the xsl:output line. By default it is xml/xhtml but you can also force it to be old-style html output.
Your macro would look something like the following (replacing 'myfield' with the alias of the property you wish to display and was used as the field= parameter in the original umbraco:Item tag you've replaced with this macro).
You could certainly make this macro more intelligent by passing the field you wish to display and having a propertyType picker as a macro parameter. But the first step is to make it work, then make it work better ;)
convertLineBreaks with HTML 4.01 strict doc type
Hi Guys,
I've added an umbraco:Item control to render some text to the page. I want to replace newlines with <br> tags, however the built in convertLineBreaks method always returns <br/>. The problem is, I'm using the HTML 4.01 strict docytype so need it to output <br> in order the validate. Anyone know how to change it's output?
Many thanks
Matt
I haven't used html (rather than xhtml) in years so I haven't tried this to be sure, but I think that if you used an xslt macro you could get the effect you want.
Shout if you need more details of the steps, but here is the basic idea...
Create a new xslt macro and use the 'clean' template. Then add some xsl:value-of statements for the fields you want to display (more on this in a moment). In your template where you now have the umbraco:Item, delete that line and replace it with a call to your macro instead. The macro will create the output and place that output into your template just as the umbraco:Item had done.
Now, the key with your xslt macro is that you A) want to convert the linebreaks, and B) want the output to be in html-compliant format, not xhtml. The first step is easy as there's a built-in library function (umbraco.library:ReplaceLineBreaks()), and the second is easy because you can specify the output format of your xslt in the xsl:output line. By default it is xml/xhtml but you can also force it to be old-style html output.
Your macro would look something like the following (replacing 'myfield' with the alias of the property you wish to display and was used as the field= parameter in the original umbraco:Item tag you've replaced with this macro).
You could certainly make this macro more intelligent by passing the field you wish to display and having a propertyType picker as a macro parameter. But the first step is to make it work, then make it work better ;)
cheers,
doug.
Thanks doug.
Thats perfect.
Matt
You're welcome!
If it resolves the problem please be sure to mark the solution for the benefit of next person with the same question.
cheers,
doug.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.