Copied to clipboard

Flag this post as spam?

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


  • Jordy Vialoux 73 posts 103 karma points
    Aug 10, 2012 @ 01:57
    Jordy Vialoux
    0

    Get Image through media picker XSLT

    Hi Guys,

    I'm wanting to get an image through the umbraco "media picker".

    I know how to bring an image through for a "for-each loop" - here is the code I use:

          <xsl:for-each select="$currentPage/NODENAMEHERE">
              <li>
                <xsl:if test="genericImageProperty &gt; 0">
                  <xsl:variable name="img" select="umbraco.library:GetMedia(genericImageProperty, 0)" />
                  <xsl:variable name="imgPath" select="concat(substring-before($img/umbracoFile,'.'), '.jpg')" />
                  <img class="person-image" src="/ImageGen.ashx?image={$imgPath}&amp;width=150&amp;" alt="{@nodeName}" />
                </xsl:if>
              </li>
          </xsl:for-each>
            

    However, now I am wanting to get an image the same way but WITHOUT using a for-each loop.

    I am using Umbraco 4.7.2 

    All suggestions welcome! 

    Jordy

     

     

     

     

     

     

     

     

    However now I am wanting to get an image WITHOUT using a for-each loop

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 10, 2012 @ 04:50
    Tom Fulton
    1

    Hi Jordy,

    If you know the ID of the media, maybe from a media picker etc, you can use the GetMedia XSLT extension.  Here's an example from Lee Kelleher's blog post, How to use umbraco.library:GetMedia in XSLT for Umbraco v4.5 

     

        <xsl:variable name="mediaId" select="number($currentPage/mediaId)" />
        <xsl:if test="$mediaId > 0">
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
            <xsl:if test="$mediaNode/umbracoFile">
                <img src="{$mediaNode/umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}" />
            </xsl:if>
        </xsl:if>

    This is assuming you have a media picker property on your current page with the alias mediaId

    Hope this helps,

    Tom 

Please Sign in or register to post replies

Write your reply to:

Draft