In the xsl:when you check if your primary field has any data. If it has you output the data. If it's empty the data from the alternative field is fetched instead.
Thanks for the replies. I marked Lee's post as answe since he was faster and I personally like casting to a string better than using string-length, although that isn't based on anything.
useIfEmpty alternative for xslt
Hi there,
A while back someone suggested the following template code for me which I've been using quite a while:
<umbraco:Item field="alternativeTitle" useIfEmpty="pageName" runat="server"></umbraco:Item>
It uses the alternative title if it's set, otherwise it will use the page name instead.
Now I would like to do the same in xslt, is this possible?
Thanks!
Hi SaphuA,
You could write an XSLT extension to handle this in a single line, but to do it natively in XSLT, you can use an <xsl:choose>:
Cheers, Lee.
Hi
Yes it's possible to do with XSLT as well.
You simply just make a choose section, which could look like this
In the xsl:when you check if your primary field has any data. If it has you output the data. If it's empty the data from the alternative field is fetched instead.
Hope this makes sense.
/Jan
Once again I'm just too slow...:)
@Jan, you know I was thinking when I posted mine... "wonder if anyone else is answering this at the same time?" ;-D (I've voted for you!)
Thanks for the replies. I marked Lee's post as answe since he was faster and I personally like casting to a string better than using string-length, although that isn't based on anything.
Thanks!
is working on a reply...