Copied to clipboard

Flag this post as spam?

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


  • Niklas Hjelm 104 posts 125 karma points
    May 01, 2010 @ 17:00
    Niklas Hjelm
    0

    Get recursive image

    Hi
    Im trying to inherit a image value and can get the id value working fine using

    <xsl:value-of select="$currentPage/ancestor-or-self::node [string(data[@alias='headerImage'])!=''] [1] /data[@alias='headerImage']"/>

    which gives me the id. How do i parse this using /data[@alias='umbracoFile so I can see the image? Can't seem to get the syntax working

    Thanks / Niklas

  • Dan 1288 posts 3921 karma points c-trib
    May 01, 2010 @ 17:11
    Dan
    0

    Here's a good approach from Lee Kelleher's blog, which is a "super safe" way to do it i.e. handles eventualities where the id isn't present etc:

    <xsl:template match="/">
    <xsl:variable name="mediaId" select="number($currentPage/data[@alias='mediaId'])" />
    <xsl:if test="$mediaId &gt; 0">
    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
    <xsl:if test="count($mediaNode/data) &gt; 0">
    <xsl:if test="string($mediaNode/data[@alias='umbracoFile']) != ''">
    <img src="{$mediaNode/data[@alias='umbracoFile']}" alt="[image]">
    <xsl:if test="string($mediaNode/data[@alias='umbracoHeight']) != ''">
    <xsl:attribute name="height">
    <xsl:value-of select="$mediaNode/data[@alias='umbracoHeight']" />
    </xsl:attribute>
    </xsl:if>
    <xsl:if test="string($mediaNode/data[@alias='umbracoWidth']) != ''">
    <xsl:attribute name="width">
    <xsl:value-of select="$mediaNode/data[@alias='umbracoWidth']" />
    </xsl:attribute>
    </xsl:if>
    </img>
    </xsl:if>
    </xsl:if>
    </xsl:if>
    </xsl:template>

    It looks a lot more intimidating than it really is, as it does check for loads of things rather than just 'get the media item from the id' but you should be able to easily trim it down if you do consider it overkill at all.

    Hope this helps...

  • Niklas Hjelm 104 posts 125 karma points
    May 02, 2010 @ 10:37
    Niklas Hjelm
    0

    Thanks for the tip. Using

    <xsl:variable name="mediaId" select="number($currentPage/ancestor-or-self::node [string(data[@alias='headerImage'])!=''] [1] /data[@alias='headerImage'])"/>

    works like a charm :)

    / Niklas

Please Sign in or register to post replies

Write your reply to:

Draft