This is working (thanks to Jan Skovgaard), but taking this a step further, I would like that a default banner image is rendered if the user didn't set a banner image for the page.
I thougt that a value set in the master contentplaceholder is used a a default when no content is available in the child content control, but apparantly this is not the case. If I don't set a banner image on a page in the Umbraco backoffice, no default banner image is rendered.
You are right about the part where you thought that the content written inside of the ContentPlaceHolder is rendered if no other content is inserted, but in your case there's always some content inside the asp:Content, since the macro is inserted. So you need to insert the default image inside of the macro instead of putting it in the ContentPlaceHolder.
Could you show us the content from the macro and we'll find a solution to this?
I first tried to use to <xsl:if> statements, one that test if $currentPage/banner has a value, an one that tests if $currentPage/banner doesn't have a value, but your solution using the <xsl:choose> statement is better.
Master template not showing default value
Hi,
For the banner of a website, I use a content placeholder in the master template, like this:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<asp:ContentPlaceHolder Id="FlexisleBannerPlaceHolder" runat="server">
<img src="/images/flexisle_header1.png" alt="" width="980" height="209" border="0" />
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
Then in the child template, I try to load a dynamic banner image using a macro:
<asp:Content ContentPlaceHolderId="FlexisleBannerPlaceHolder" runat="server">
<umbraco:Macro Alias="GetBannerImage" runat="server"></umbraco:Macro>
</asp:Content>
This is working (thanks to Jan Skovgaard), but taking this a step further, I would like that a default banner image is rendered if the user didn't set a banner image for the page.
I thougt that a value set in the master contentplaceholder is used a a default when no content is available in the child content control, but apparantly this is not the case. If I don't set a banner image on a page in the Umbraco backoffice, no default banner image is rendered.
Am I getting something wrong here?
Thanks for your advice,
Anthony Candaele
Belgium
Hi Anthony
You are right about the part where you thought that the content written inside of the ContentPlaceHolder is rendered if no other content is inserted, but in your case there's always some content inside the asp:Content, since the macro is inserted. So you need to insert the default image inside of the macro instead of putting it in the ContentPlaceHolder.
Could you show us the content from the macro and we'll find a solution to this?
/Kim A
Oh I didn't think of it that way.
This is the code of my getbannerimage.xslt file:
<xsl:template match="/">
<xsl:if test="$currentPage/banner != ''">
<img src="{umbraco.library:GetMedia($currentPage/banner, false() )/umbracoFile}" alt="{umbraco.library:GetMedia($currentPage/banner, false() )/alternativeText}" />
</xsl:if>
</xsl:template>
Thanks for helping me out .... again :)
Anthony
Try changing the code to something like this:
/Kim A
Hi Anthony
you need to use the ancestor-of-self axe.
Like this: $currentPage/ancestor-or-self::*/banner
This way the value from the ancestor is used if no value is entered in the field on the current page.
If the nearest ancestor does not have any value it goes one step higher to see if there is a value. Untill it reaches the level 1 node.
Hope this makes sense.
/Jan
Hi Kim,
Proble solved ... again :)
I first tried to use to <xsl:if> statements, one that test if $currentPage/banner has a value, an one that tests if $currentPage/banner doesn't have a value, but your solution using the <xsl:choose> statement is better.
Thanks a lot,
Anthony
Great to hear that Anthony. You could use two if-statements as well, but in that situation I'd also go for the choose-statement instead :)
/Kim A
@Jan: That's a very elegant solution indeed, I implemented it and it works!
Thanks a lot,
Anthony
@Jan,
Hi Jan, I just discovered this. I implemented your suggestion like this:
<xsl:if test="$currentPage/ancestor-or-self::*/banner != ''">
<img src="{umbraco.library:GetMedia($currentPage/ancestor-or-self::*/banner, false() )/umbracoFile}" alt="{umbraco.library:GetMedia($currentPage/ancestor-or-self::*/banner, false() )/alternativeText}" />
</xsl:if>
But now my child page is always showing the banner image of the parent page, even if a banner images was set for the child page.
Have I not implemented your suggestion the right way?
Thanks for your advice,
Anthony
Anthony, could you try changing the code to this:
/Kim A
Hi,
I tested the code, but it is not working. Page for which no banner image is set are not showing the banner image of their parent.
I have a version of the website on my staging server:
http://195.130.154.107/
Anthony
is working on a reply...