using xslt and getMedia to get file path of a media picker image
hi,
I have a content type that has a title and a thumbnail. Title is text, and thumbnail is a media picker. Using the xslt above, I can get an unordered list of title and thumbnail (which are numeric id's) printed to the screen. The third value-of call that uses the GetMedia doesn't work for me. It's always blank.
<!-- Don't change this, but add a 'contentPicker' element to --> <!-- your macro with an alias named 'source' --> <xsl:variable name="source" select="/macro/source"/>
<xsl:template match="/">
<!-- The fun starts here --> <ul> <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '-1']"> <li> <span> <xsl:value-of select="./title"/> - <xsl:value-of select="./thumbnail"/> - <xsl:value-of select="umbraco.library:GetMedia(./thumbnail,0)/data [@alias='umbracoFile']" /> </span> </li> </xsl:for-each> </ul>
</xsl:template>
</xsl:stylesheet>
can someone please help? when ./title and ./thumbnail both print the title and media id, shouldn't the getMedia call get the file path of the image as well?
Just happy you found the solution to your problem.
It's a comon mistake to mix the two schemas since there are many samples based on the legacy schema out there and sometimes one forgets to amend them to use the new schema.
Zagros, if you want to see some examples of the new XML schema you can take a look in the Wiki here. The XML schema changed in v4.5, and in v4.5.1 the schema for media items changed a bit again. But you haven't quite got the grab of the new schema, I'd suggest that you try to print out the XML in a textarea like this:
By the way Zagros. I guess that you don't want to iterate through the nodes that has the umbracoNaviHide property checked, right?
Then you need to change the for-each to this:
<xsl:for-eachselect="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
The only thing that I've changed is that -1 should be 1. When a true/false data type is checked, it's set to 1 and otherwise it's set to 0. Just a small thing, but I just wanted to let you know :)
using xslt and getMedia to get file path of a media picker image
hi,
I have a content type that has a title and a thumbnail. Title is text, and thumbnail is a media picker. Using the xslt above, I can get an unordered list of title and thumbnail (which are numeric id's) printed to the screen. The third value-of call that uses the GetMedia doesn't work for me. It's always blank.
can someone please help? when ./title and ./thumbnail both print the title and media id, shouldn't the getMedia call get the file path of the image as well?
Hi Zagros
You need to change this line:
to this:
this should give you the path to the image printet to the screen. You had used some XSLT code that only worked with the legacy schema.
Besides that, you should probably check to see if the thumbnail-property is empty or not, to prevent the GetMedia extension of generating an error :)
/Kim A
Hi Zagros
It's probably because you're mixing the two XML schemas :-)
In the following you use the old data[@alias='umbracoFile'] syntax
<xsl:value-of select="umbraco.library:GetMedia(./thumbnail,0)/data [@alias='umbracoFile']" />
With the new schema it should read this
<xsl:value-of select="umbraco.library:GetMedia(./thumbnail,0)/umbracoFile" />
Hope this helps.
/Jan
where was this info??....
to be honest i just came back to say I tried it knowing xslt and came to post the solution and saw your reply...
Hi Zagros
Just happy you found the solution to your problem.
It's a comon mistake to mix the two schemas since there are many samples based on the legacy schema out there and sometimes one forgets to amend them to use the new schema.
/Jan
Zagros, if you want to see some examples of the new XML schema you can take a look in the Wiki here. The XML schema changed in v4.5, and in v4.5.1 the schema for media items changed a bit again. But you haven't quite got the grab of the new schema, I'd suggest that you try to print out the XML in a textarea like this:
if you want to see the XML of the current page.
You can check out the returned XML from the GetMedia extension like this:
/Kim A
...And if one is a bit lazy the XML dump package http://our.umbraco.org/projects/developer-tools/xml-dump is another great option to see the XML structure.
/Jan
By the way Zagros. I guess that you don't want to iterate through the nodes that has the umbracoNaviHide property checked, right?
Then you need to change the for-each to this:
The only thing that I've changed is that -1 should be 1. When a true/false data type is checked, it's set to 1 and otherwise it's set to 0. Just a small thing, but I just wanted to let you know :)
/Kim A
thanks good catch,
I forgot to change that back after experimenting
is working on a reply...