CodeGarden 10: The sixth annual Umbraco Developer Conference
June 23-25th 2010 - free ASP.NET MVC pre-conference. Register today!

GetMedia

The method is used to get information of files in the media library - such as filename, size, height, width.

Parameters

GetMedia(int MediaId, bool Deep);

  Integer   MediaId 
Boolean   Deep

Return value

The method returns a XPathNodeIterator with the information of selected file.

Usage

<xsl:value-of select="umbraco.library:GetMedia(./data [@alias = 'yourProperty'], 0)"/>

Getting the url of a media file with hardcoded ID

<xsl:value-of select="umbraco.library:GetMedia(1057, 0)/data [@alias = 'umbracoFile']"/>

Getting the url of a media file using a mediaPicker

<xsl:value-of select="umbraco.library:GetMedia($currentPage/data[@alias='yourProperty'], 0)/data [@alias = 'umbracoFile']"/>

How to render an image from XSLT

Assuming the property alias is 'bannerImage' then:

 <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/data[@alias='bannerImage'], 0)/data" />

 <xsl:if test="$media">
  <xsl:variable name="url" select="$media [@alias = 'umbracoFile']" />
  <xsl:variable name="width" select="$media [@alias = 'umbracoWidth']" />
  <xsl:variable name="height" select="$media [@alias = 'umbracoHeight']" />
  <img src="{$url}" width="{$width}" height="{$height}" />
 </xsl:if>

PLEASE NOTE: This has been copied directly from the old Umbraco Wiki. Kudos to the original poster.