Copied to clipboard

Flag this post as spam?

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


  • Roger 195 posts 474 karma points
    Jan 30, 2013 @ 21:31
    Roger
    0

    Display Macro on all pages from Master Template

    Hi all,

    Just a quick one.

    I have 3 boxes that contain content and an image that I want to show on all pages.

    The boxes are updated from a node directly under the content node (see image)

    The boxes show fine on the Homepage only. The Macro is in the Master Template.

    I think My XSLT is wrong and is only selecting from a certain level. Here's my code:

    I think the issue is in the variable select??

    <xsl:variable name="sectionNode" select="$currentPage/parent::*/child::*[@level=1]"/>

    <div id="sections">
          <xsl:for-each select="$sectionNode/child::SectionBox">
             
                  <div>
            <xsl:attribute name="class">section-<xsl:value-of select="@urlName"/></xsl:attribute>
                       <xsl:if test="current()/umbracoMediaFile != ''">
                            <xsl:variable name="umbracoMediaFile" select="umbraco.library:GetMedia(current()/umbracoMediaFile, 'false')" />
                          <div class="section-image">
                              <img src="{$umbracoMediaFile/umbracoFile}" width="276" height="144" alt="Homepage section image"/>
                            </div>
                       </xsl:if>

                      <h2><xsl:value-of select="contentBoxHeading"/></h2>
                      <xsl:value-of select="contentBoxText" disable-output-escaping="yes"/>
                    <a title="More details" class="more" >
                        <xsl:attribute name="href">/<xsl:value-of select="@nodeName"/></xsl:attribute>
                        More</a>
                      </div>   
          </xsl:for-each>
      
        </div>   

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Jan 30, 2013 @ 23:20
    Chriztian Steinmeier
    100

    Hi Roger,

    Yes, you're right - the issue is with your initial sectionNode variable, because it will only go up one level and then down again, but only selecting the final node if it's at level 1 - so you really need to specifically select that "Homepage Boxes" node.

    I've assumed its alias is SectionBoxes (and that it's the only one of that kind at that level) - change the code accordingly so it works as it should. I took the liberty of changing a couple of other things too (purely for readability) - try to see if you can see for yourself what they are - and don't hesitate to ask why, if you're curious :-)

    <xsl:variable name="sectionNode" select="$currentPage/ancestor::root/SectionBoxes"/>
    
    <div id="sections">
       <xsl:for-each select="$sectionNode/SectionBox">
          <div class="section-{@urlName}">
             <xsl:if test="normalize-space(umbracoMediaFile)">
                <xsl:variable name="umbracoMediaFile" select="umbraco.library:GetMedia(current()/umbracoMediaFile, false())" />
                <div class="section-image">
                   <img src="{$umbracoMediaFile/umbracoFile}" width="276" height="144" alt="Homepage section image" />
                </div>
             </xsl:if>
             <h2><xsl:value-of select="contentBoxHeading" /></h2>
             <xsl:value-of select="contentBoxText" disable-output-escaping="yes" />
             <a href="/{@nodeName}" title="More details" class="more">More</a>
          </div>
       </xsl:for-each>
    </div>

    /Chriztian

  • Roger 195 posts 474 karma points
    Jan 30, 2013 @ 23:35
    Roger
    0

    Chriztian your a genius! Thank you!

    Works perfect, just one slight query if I may?

    The link for more details is a content picker and I need the user to have the ability to choose any page and link to it but I fear the path to the page in my link currently /{@nodeName} writes the sction box node name to screen,

    I also see the other changes you have made. This is a big help, many thanks, I have lots to learn with xslt!

    <ahref="/{@nodeName}"title="More details"class="more">More</a>
  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Jan 30, 2013 @ 23:46
    Chriztian Steinmeier
    1

    Hi Roger - thanks, you're welcome :-)

    If you have a content picker, all you need to do is use the NiceUrl() extension to get the correct link, e.g.:

    <a href="{umbraco.library:NiceUrl(contentBoxLink)}">More</a>

    (Again, you'll need to use the correct alias - I'm just taking a well-founded guess here :-)

    You'll probably need to make sure that a page was selected, since NiceUrl() will fail horribly (just like the GetMedia() one does) if no ID is present... 

    /Chriztian

     

  • Roger 195 posts 474 karma points
    Jan 30, 2013 @ 23:53
    Roger
    0

    Perfect!!

    Thanks so much for the help again Chriztian.

    All the best

    Roger

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies