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.
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:
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?
Hi Ciprian,
To select an element by name, use the name() function:
/Chriztian
Thanks a lot! That works great.
I also added a test so it won't give any parsing errors.
This is the final version:
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>
is working on a reply...