Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Candaele 1197 posts 2049 karma points
    Feb 12, 2011 @ 15:39
    Anthony Candaele
    0

    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

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 12, 2011 @ 15:50
    Kim Andersen
    0

    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

  • Anthony Candaele 1197 posts 2049 karma points
    Feb 12, 2011 @ 15:56
    Anthony Candaele
    0

    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

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 12, 2011 @ 15:58
    Kim Andersen
    0

    Try changing the code to something like this:

    <xsl:template match="/">
    <xsl:choose>
    <xsl:when test="$currentPage/banner != ''">
       <img src="{umbraco.library:GetMedia($currentPage/banner, false() )/umbracoFile}" alt="{umbraco.library:GetMedia($currentPage/banner, false() )/alternativeText}" />
    </xsl:when>
    <xsl:otherwise>
    <img src="/images/flexisle_header1.png" alt="" width="980" height="209" border="0" />
    </xsl:otherwise>
    </xsl:choose>
         
    </xsl:template>

    /Kim A

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 12, 2011 @ 16:00
    Jan Skovgaard
    1

    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

  • Anthony Candaele 1197 posts 2049 karma points
    Feb 12, 2011 @ 16:07
    Anthony Candaele
    0

    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

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 12, 2011 @ 16:09
    Kim Andersen
    0

    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

  • Anthony Candaele 1197 posts 2049 karma points
    Feb 12, 2011 @ 16:31
    Anthony Candaele
    0

    @Jan: That's a very elegant solution indeed, I implemented it and it works!

    Thanks a lot,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Feb 12, 2011 @ 17:39
    Anthony Candaele
    0

    @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

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 12, 2011 @ 18:35
    Kim Andersen
    0

    Anthony, could you try changing the code to this:

    <xsl:if test="$currentPage/ancestor-or-self::*[1]/banner != ''">
        <img src="{umbraco.library:GetMedia($currentPage/ancestor-or-self::*[1]/banner, false() )/umbracoFile}" alt="{umbraco.library:GetMedia($currentPage/ancestor-or-self::*[1]/banner, false() )/alternativeText}" />
    </xsl:if>

    /Kim A

  • Anthony Candaele 1197 posts 2049 karma points
    Feb 13, 2011 @ 10:25
    Anthony Candaele
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft