Copied to clipboard

Flag this post as spam?

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


  • Rachel Skuse 88 posts 118 karma points
    Aug 08, 2011 @ 15:36
    Rachel Skuse
    0

    How do I 'GetMedia' item specified in another page??

    Hi,

    I am using the code below, on a homepage, to display a banner (there's more code and it scrolls through various images)

    <xsl:variable name="media1" select="umbraco.library:GetMedia($currentPage/data[@alias='slide1'], 0)" />    
    <xsl:if test="$currentPage/data[@alias='slide1'] != ''">
    <img id="slide1" class="slideimg" src="{$media1/data[@alias='largeSlide']}" alt="{$media1/data[@alias='overlayHeading']}" />
    </xsl:if>

    How do I use this code on other pages throughout the site but still referencing the images (eg. Slide1) that are specified on the homepage?

    Thanks :)

    Rachel

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 08, 2011 @ 15:47
    Tom Fulton
    0

    Hi Rachel,

    Assuming all of your other pages are beneath the homepage, you can use the ancestor-or-self axis to find the homepage and retrieve properties from it..something like:

    <xsl:if test="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Homepage']/data[@alias='slide1'] != ''">
          <xsl:variable name="media1" select="umbraco.library:GetMedia($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Homepage']/data[@alias='slide1'], 0)" />   
         <img id="slide1" class="slideimg" src="{$media1/data[@alias='largeSlide']}" alt="{$media1/data[@alias='overlayHeading']}" />
    </xsl:if>

    Replacing 'Homepage' with the alias of your "Homepage" document type.

    -Tom

  • Rachel Skuse 88 posts 118 karma points
    Aug 08, 2011 @ 16:00
    Rachel Skuse
    0

    Thanks Tom but unfortunately my pages are not child pages of the homepage - is there another way around this?

    Rach

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 08, 2011 @ 16:25
    Tom Fulton
    1

    Yes it's possible, you just need to start at the root, unfortunately I'm not sure of the exact syntax since it looks like you are using the legacy XML schema.  But I think this might work:

    <xsl:if test="$currentPage/ancestor::root/node [@nodeTypeAlias = 'Homepage']/data[@alias='slide1'] != ''">
          <xsl:variable name="media1" select="umbraco.library:GetMedia($currentPage/ancestor::root/node [@nodeTypeAlias = 'Homepage']/data[@alias='slide1'], 0)" />   
         <img id="slide1" class="slideimg" src="{$media1/data[@alias='largeSlide']}" alt="{$media1/data[@alias='overlayHeading']}" />
    </xsl:if>

    (assuming your Homepage is directly beneath the root Content node)

    -Tom

  • Rachel Skuse 88 posts 118 karma points
    Aug 08, 2011 @ 16:31
    Rachel Skuse
    0

    That code works perfectly! Thanks Tom :)

Please Sign in or register to post replies

Write your reply to:

Draft