Copied to clipboard

Flag this post as spam?

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


  • Ciprian 17 posts 38 karma points
    Aug 19, 2010 @ 10:42
    Ciprian
    0

    Making a macro that displays images based on a parameter

    Hey guys!

    I'm trying to make a macro that recieves the image alias of an image added with a media picker as a parameter and then displays the image.

    Here's my code so far:

    <xsl:variable name="imageAlias">
      <xsl:value-of select="/macro/imgAlias" />
    </xsl:variable>
    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/$imageAlias, 0)"/>
    <img src="{$media/umbracoFile}" alt="{$media/altText}" />

    The problem is that it won't accept the variable $imageAlias in the path $currentPage/$imageAlias.

    I can make this work if I use ifs but that would make this macro site specific, I'd like to be able to use it in any site, just to specify the alias and have the image in the page.

    Any ideas?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 19, 2010 @ 10:52
    Chriztian Steinmeier
    0

    Hi Ciprian,

    To select an element by name, use the name() function:

    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/*[name() = $imageAlias], 0)" />

    /Chriztian

  • Ciprian 17 posts 38 karma points
    Aug 19, 2010 @ 11:02
    Ciprian
    0

    Thanks a lot! That works great.

    I also added a test so it won't give any parsing errors.

    This is the final version:

    <xsl:variable name="imageAlias">
      <xsl:value-of select="/macro/imgAlias" />
    </xsl:variable>
    <xsl:if test="$currentPage/*[name() = $imageAlias] !=''">
      <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/*[name() = $imageAlias], 0)"/>
      <img src="{$media/umbracoFile}" alt="{$media/altText}" />
    </xsl:if>
  • manikandan 7 posts 27 karma points
    May 08, 2012 @ 15:13
    manikandan
    0

    Hi all,

    i am also doing the same thing as per above post. but i did't got any output

    /macro/sourcePath => /header/imagewithlink/imageurl

    <xsl:template match="/">
      <xsl:variable name="imageAlias">
      <xsl:value-of select="/macro/sourcePath" />
    </xsl:variable>

      <xsl:if test="$currentPage/ancestor-or-self::root/*[name() = $imageAlias] !=''">
        <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/*[name() = $imageAlias], 0)"/>
        <img src="{$media/umbracoFile}" />
      </xsl:if>

Please Sign in or register to post replies

Write your reply to:

Draft