How to use umbraco.library GetMedia in XSLT for Umbraco v4.5
This is a quick follow-up on my previous 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>
Any questions? Come join us over at Our Umbraco… we are a friendly bunch!