I'm guessing you want to only show the header image if the for-each expression following it will output something, right?
In that case, it's very important that you store that result in a variable so you're not repeating it (true for any language, really - not just XSLT) - otherwise, when you (or someone else in a month) need to change the expression, it's very easy to forget to change it in the if statement as well, especially if the header image becomes a header section - you know how it goes :)
I've also put the <ul> inside the if statement because you normally wouldn't want an empty <ul /> in the output anyway. (But you example may have been shortened for this post of course, in which case you should ignore that).
Thanks guys. Dirk I was getting some error so I tried Chriztians solution and it worked so I marked it solved. I really appreciate the very helpful community here.
How can I add an if statement?
I am using the List_Sub_Pages_By_Level macro and was wondering how I can show a headerimage only if there are results? Below is what I have so far:
<xsl:if test="SomeExpression">
<img src="http://myheaderimage.png"/>
</xsl:if>
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
you can perform a count() on your for-each expression to check if there are results and show if count() > 0
Cheers,
Dirk
Hi Donald.
When you are saying results, did you mean childs, if so I think that you could something like this.
If you are getting the image from Umbraco by a media picker and want to be possible to set an image each page you can do something like:
Where the bannerImage is the alias of your property, for the media picker. the documentation for the Media Picker http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors/Media-Picker and GetMedia library method can be found here: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
And as you probably know there are some different axes in Umbraco parent, children ect. http://our.umbraco.org/wiki/reference/xslt/xpath-axes-and-their-shortcuts
And here is the documentation of what Currentpage represent: http://our.umbraco.org/wiki/reference/xslt/understanding-currentpage
Hope this can help you in the right direction.
/Dennis
Hi Donald,
I'm guessing you want to only show the header image if the for-each expression following it will output something, right?
In that case, it's very important that you store that result in a variable so you're not repeating it (true for any language, really - not just XSLT) - otherwise, when you (or someone else in a month) need to change the expression, it's very easy to forget to change it in the if statement as well, especially if the header image becomes a header section - you know how it goes :)
I'd do more than one, actually:
I've also put the
<ul>
inside the if statement because you normally wouldn't want an empty<ul />
in the output anyway. (But you example may have been shortened for this post of course, in which case you should ignore that)./Chriztian
Thanks guys. Dirk I was getting some error so I tried Chriztians solution and it worked so I marked it solved. I really appreciate the very helpful community here.
you got it working, that's the important thing!, at least you get to experience a great community ;)
is working on a reply...