I have a media picker (am using the improved media picker) and I want to be able to select an image and have this displayed on the page.
All is well up to a point. I can pass the mediaID through to the XSLT, find the media item and return the URL.
The problem occurs when I want to get umbracoHeight and umbracoWidth - these always return an empty string. I'm hoping someone may be able to help me with this or offer some advice if I am getting this fundamentally wrong.
Code in template: <umbraco:MacromediaID="[#FooterLogos]"Alias="GetFooterImageFile"runat="server"></umbraco:Macro>
returns an empty string which is why I had to use my original code. I did look through Lee's post but cannot get it to work and am unable to find any complete examples of what I wish to receive - I'm lost with this.
Media picker - xslt
Hi,
I have a media picker (am using the improved media picker) and I want to be able to select an image and have this displayed on the page.
All is well up to a point. I can pass the mediaID through to the XSLT, find the media item and return the URL.
The problem occurs when I want to get umbracoHeight and umbracoWidth - these always return an empty string. I'm hoping someone may be able to help me with this or offer some advice if I am getting this fundamentally wrong.
Code in template:
<umbraco:Macro mediaID="[#FooterLogos]" Alias="GetFooterImageFile" runat="server"></umbraco:Macro>
Code in XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt"xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="mediaID" select="macro/mediaID" />
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:variable name="media" select="umbraco.library:GetMedia($mediaID, 0)/data [@alias = 'umbracoFile']" />
<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}" />
<xsl:value-of select="$media [@alias = 'umbracoWidth']"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Thanks in advance
You should probably change it to something this:
<xsl:variable name="media" select="umbraco.library:GetMedia($mediaID, 0)" />
<xsl:if test="($media) != ''">
<xsl:variable name="url" select="$media/data [@alias = 'umbracoFile']" />
<xsl:variable name="width" select="$media/data [@alias = 'umbracoWidth']" />
<xsl:variable name="height" select="$media/data [@alias = 'umbracoHeight']" />
<img src="{$url}" />
<xsl:value-of select="$media [@alias = 'umbracoWidth']"/>
</xsl:if>
Also check out Lee Kelleher's excellent blogpost about media items in xslt.
Thanks for posting.
Using
returns an empty string which is why I had to use my original code.
I did look through Lee's post but cannot get it to work and am unable to find any complete examples of what I wish to receive - I'm lost with this.
Ah, I see, my bad, try this one:
Ehm, or rather this one:
Aha! - I see my folly.
That works (and makes sense too) - thank you kindly for your valuable time.
No problem! We've all been there staring ourselves blind on something. ;)
is working on a reply...