umbraco.library:GetMedia($mediaFolderID, 'false') ... returns A LOT
Hello
I need to display some media files. There are aprox. 2000 files. The parent node got the id 6207. How can I selext just this one node to use with XPATH? I cannot use the umbraco.library:GetXmlNodeById since it is a Media-folder and therefore unpublished... only choice is then umbraco.library:GetMedia I guess.
When I do this:
<!-- get folder ID, actually from a field but hardcoded here --> <xsl:variable name="mediaFolderID" select="6207" />
<!-- This next step takes 4-5 sec! --> <!--get the node in the Media structure with the ID given above --> <xsl:variable name="images" select="umbraco.library:GetMedia($mediaFolderID, 'false')" />
<!-- print out the GetMedia call to see what is wrong --> <xsl:value-of select="umbraco.library:GetMedia($mediaFolderID, 'false')"/>
When printing out the GetMedia all links for all files in the subfolders to '6207' and not just the one node that I need. And because there are 1500-2000 files it takes abour 4-5 sec to do a GetMedia...
Am I doing this wrong? It takes a long time to complete a simple reload of the page.
I just need to get a node form the Media section that I can do a for-each into.
I just put the following into my XSLT and it works (I wasn't sure what you wanted to do with the media files but this is just showing them as pictures). This would just go through all the nodes directly under 6207 and display them if they actually have a link (so, not folders). I think yours was having to put the whole node structure under 6207 into the variable, which was taking awhile.
I think the problem is with the second parameter (Deep) of GetMedia. Since it requires a Boolean, the value 'false' might not work, (actually it doesn't I've tested it). So instead try:
The zero will be cast as a false ... you could even use false(), it's up to you.
The Deep parameter is intended to return all the child nodes of the media node... which is great for folder types (with a small number of nodes). Obviously you're seeing the performance hit when it's returning (approx) 2000 child nodes.
You're being bit by the creepy monster of booleans in XSLT - you have to send false() as the parameter (or a plain zero) - when using 'false', you're sending a string, which always evaluates to the boolean value true... so to get only the single node, do:
Also, if you want to see the exact output from the method then use the <xsl:copy-of select="umbraco.library....." /> instead of the xsl:value-of. Then it will output the xml source of the method, wo you can see the data you are working on.
umbraco.library:GetMedia($mediaFolderID, 'false') ... returns A LOT
Hello
I need to display some media files. There are aprox. 2000 files. The parent node got the id 6207. How can I selext just this one node to use with XPATH? I cannot use the umbraco.library:GetXmlNodeById since it is a Media-folder and therefore unpublished... only choice is then umbraco.library:GetMedia I guess.
When I do this:
<!-- get folder ID, actually from a field but hardcoded here -->
<xsl:variable name="mediaFolderID" select="6207" />
<!-- This next step takes 4-5 sec! -->
<!--get the node in the Media structure with the ID given above -->
<xsl:variable name="images" select="umbraco.library:GetMedia($mediaFolderID, 'false')" />
<!-- print out the GetMedia call to see what is wrong -->
<xsl:value-of select="umbraco.library:GetMedia($mediaFolderID, 'false')"/>
When printing out the GetMedia all links for all files in the subfolders to '6207' and not just the one node that I need. And because there are 1500-2000 files it takes abour 4-5 sec to do a GetMedia...
Am I doing this wrong? It takes a long time to complete a simple reload of the page.
I just need to get a node form the Media section that I can do a for-each into.
BR. Anders
I just put the following into my XSLT and it works (I wasn't sure what you wanted to do with the media files but this is just showing them as pictures). This would just go through all the nodes directly under 6207 and display them if they actually have a link (so, not folders). I think yours was having to put the whole node structure under 6207 into the variable, which was taking awhile.
<xsl:variable name="mediaFolderID" select="6207" /> <xsl:for-each select="umbraco.library:GetMedia($mediaFolderID, 'false')/node"> <xsl:if test="./data [@alias = 'umbracoFile'] != 0"> <img src="{./data [@alias = 'umbracoFile']}" /> </xsl:if> </xsl:for-each>
Hi Anders,
I think the problem is with the second parameter (Deep) of GetMedia. Since it requires a Boolean, the value 'false' might not work, (actually it doesn't I've tested it). So instead try:
The zero will be cast as a false ... you could even use false(), it's up to you.
The Deep parameter is intended to return all the child nodes of the media node... which is great for folder types (with a small number of nodes). Obviously you're seeing the performance hit when it's returning (approx) 2000 child nodes.
Let us know how it goes.
Good luck, Lee.
Hi Anders,
You're being bit by the creepy monster of booleans in XSLT - you have to send false() as the parameter (or a plain zero) - when using 'false', you're sending a string, which always evaluates to the boolean value true... so to get only the single node, do:
OR
/Chriztian
Darn it Lee - too quick you are :-)
/Chriztian
Chriztian, don't you hate it when we cross-post the same answer!? ;-)
I have updated the GetMedia wiki page, so that it uses zeroes (0) instead of 'false' string.
http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
Yeah - borders on the unbearable :-)
Good thinking with the Wiki - gotta have the cut 'n paste origins clean :-)
/Chriztian
If you need to do a foreach on all 2000 items in that folder, then you need to get the deep version. Otherwise you will not have any xml to loop over.
Unfotunately, that operation is costly, as it hits the database a lot. You might want to take a look at this package to get caching on media items:
http://our.umbraco.org/projects/cultiv-mediacache
Also, if you want to see the exact output from the method then use the <xsl:copy-of select="umbraco.library....." /> instead of the xsl:value-of. Then it will output the xml source of the method, wo you can see the data you are working on.
is working on a reply...