Umbraco/Samples and Articles/Macros

< Umbraco‎ | Samples and Articles

A macro for getting the url of an imageEdit

Go to Developer/XSLT Files, create a new xslt file GetImageURL with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]>
        exclude-result-prefixes="msxml umbraco.library">

<xsl:output method="xml" omit-xml-declaration="yes" />

<xsl:param name="currentPage"/>
<xsl:variable name="imageID" select="/macro/imageID/node/@id"/>

<xsl:template match="/">
  <xsl:if test="$imageID != ''">
      <xsl:attribute name="src">
        <xsl:value-of select="umbraco.library:GetMedia($imageID, 'false')/data [@alias = 'umbracoFile']"/>


Now go to Developer/Macros, create a new macro, Get Image URL, giving it the alias GetImageURL. In Use XSLT File, select the XSLT file you just created.

On Parameters, add a new parameter with the alias imageID and name Image ID. The type should be set to mediaCurrent and Show should be checked. Save the macro and your home!