Lets say I'm currently rendering an article with the property 'introduction'. In case the article introduction field is empty I want instead to output a more global field on the home site node, let's call it 'global_introduction'.
Does anybody know how to do this?
I know about the optional attribute xslt, but don't know if it will suffice... or exactly how to do it.
If you want to keep using the umbraco:Item way of doing things all you need to to is add another attribute named "useIfEmpty" and then type in the property you want to display instead. Like this: <umbraco:Item field="introduction" useIfEmpty="bodyText" runat="server" />
If you edit the templates using the editor build into Umbraco you can see the different field options by clicking the button right next to the "save" icon.
Thank you for your reply. The useIfEmpty selects a field in the same scope as the field="introduction" attribute, right? Well, what I need if the 'introduction' is empty is to select a global field set on the top node in the content hierarchy (ie. the frontpage of my site).
How to output a conditional field?
Outputting a field in Umbraco is pretty straight forward:
Lets say I'm currently rendering an article with the property 'introduction'. In case the article introduction field is empty I want instead to output a more global field on the home site node, let's call it 'global_introduction'.
Does anybody know how to do this?
I know about the optional attribute
xslt
, but don't know if it will suffice... or exactly how to do it.Hi Alex
If you want to keep using the umbraco:Item way of doing things all you need to to is add another attribute named "useIfEmpty" and then type in the property you want to display instead. Like this: <umbraco:Item field="introduction" useIfEmpty="bodyText" runat="server" />
If you edit the templates using the editor build into Umbraco you can see the different field options by clicking the button right next to the "save" icon.
Hope this helps.
/Jan
Thank you for your reply. The useIfEmpty selects a field in the same scope as the field="introduction" attribute, right? Well, what I need if the 'introduction' is empty is to select a global field set on the top node in the content hierarchy (ie. the frontpage of my site).
I assume the useIfEmpty doesn't allow XPath!?
/Alex
What if you set recursion? I'm not entirely sure how the useIfEmpty and recurse work in tandem... but might be worth investigating??
<umbraco:Item field="introduction" useIfEmpty="bodyText" recursive="true" runat="server" />
Or just jump out into macro, with more powerful logic, rather than try and use the simple umbraco item.
Setting recursive=true doesn't seem to effect the useIfEmpty value. :( This would otherwise have been what I needed!
Maybe a macro is the only way around this issue...
is working on a reply...