KNOWLEDGE BASE

How to use umbraco.library GetMedia in XSLT for Umbraco v4.5


Umbraco MVP Lee Kelleher tells us how to use GetMedia properly.

This is a quick follow-up on my blog post: "How to use umbraco.library GetMedia in XSLT". At the request of fellow Umbraco South-West UK developer, Dan, that I should update the code snippets for the new XML schema in Umbraco v4.5+

First a quick notice; if you are using v4.5.0, then please upgrade to v4.5.1, as there was a tiny bug in GetMedia that caused great confusion and headaches - you have been advised!

Without further ado, the updated XSLT snippet that you came here for…

<xsl:template match="/">
<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>
</xsl:template>

 


Need an Umbraco Master?

Here at Simon Antony, we have an in house certified Umbraco Grand Master available for hire. Got a problem with your site, need architecture advice, give us a call to speak to Simon directly and see how we can help

Contact Simon Today!