In short, you can't just call it like a regular field, because it stores the Media ID rather than the path. You need to convert the Media ID to the file path by using GetMedia to get the XML of the media node, then use the umbracoFile property.
Basically: <img src="{umbraco.library:GetMedia($currentPage/mediaId)/umbracoFile}"/> - but use Lee's code as it has good error checking.
There is no value. Which is strange since I have choosen media in the mediapicker property and I can get output from the other properties(textstrings etc)
I do believe the properties are case sensitive, it's not productImage is it?
To troubleshoot further you can look at the raw XML of the node using the code below. This will show you the XML your code is reading. If it's not there, the data isn't published or you've got some other problem :)
Put this as the first line in your loop to output the XML for the current item in the loop:
<textarea><xsl:copy-of select="."/></textarea>
Take a look at the XML inside the textarea and make sure there is a <productimage> tag with a value in it.
Display image from mediapicker property
I have a document type product that has a property(image) mediapicker in which I select an image.
When I loop through my products I wish to display the image just like i display the other properties for example:
<xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
<li>
<a>
<xsl:value-of select="description" />
</a>
</li>
</xsl:for-each>
I've tried this link but I do not get the hang of it
http://blog.leekelleher.com/2010/08/11/how-to-use-umbraco-library-getmedia-in-xslt-for-umbraco-v4-5/
Lee's code looks good, all you should need to do is change "$currentPage/mediaId" - change mediaId to the property alias of your media picker field.
The code might look a bit complicated but thats because it has some error checking and is simplified a bit for readability.
Let us know if you have any problems/questions
In short, you can't just call it like a regular field, because it stores the Media ID rather than the path. You need to convert the Media ID to the file path by using GetMedia to get the XML of the media node, then use the umbracoFile property.
Basically: <img src="{umbraco.library:GetMedia($currentPage/mediaId)/umbracoFile}"/> - but use Lee's code as it has good error checking.
Still no display...
<xsl:variable name="mediaId" select="number($currentPage/productimage)" />
<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>
productimage is the property alias
Try writing out this line at the beginning of your loop to make sure there is actually a value there.
mediaid: <xsl:value-of select="$currentPage/productimage"/>
If there is, add some text after each IF statement so you can see how far it's getting.
There is no value. Which is strange since I have choosen media in the mediapicker property and I can get output from the other properties(textstrings etc)
I do believe the properties are case sensitive, it's not productImage is it?
To troubleshoot further you can look at the raw XML of the node using the code below. This will show you the XML your code is reading. If it's not there, the data isn't published or you've got some other problem :)
Put this as the first line in your loop to output the XML for the current item in the loop:
Take a look at the XML inside the textarea and make sure there is a <productimage> tag with a value in it.
I got it to display the productimage ID(1061) now but still no display of the image
To troubleshoot, I would add some text after some of the <xsl:if statements so you can see how far the code is getting and where it is failing.
Something like:
<xsl:variable name="mediaId" select="number($currentPage/productimage)" />
<xsl:if test="$mediaId > 0">
Found mediaId...
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="$mediaNode/umbracoFile">
Found umbracoFile property...
<img src="{$mediaNode/umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}" />
</xsl:if>
</xsl:if>
Hi Fredrik
Just to be sure, is the productImage-property located on the current page or on the child nodes, that you are iterating through?
I guess that it's on the child nodes, but is that correct?
If that's the case, you should change your variable from this:
to this:
otherwise the code will try to grab the media id from the current page...
/Kim A
Kim is right..sorry Frederik, I am blind!
It works finally!
Great to hear Fredrik! Glad I could help.
/Kim A
is working on a reply...