Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anders Tillebeck 15 posts 36 karma points
    Jan 21, 2010 @ 17:26
    Anders Tillebeck
    0

    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

     

  • Seth Niemuth 275 posts 397 karma points
    Jan 21, 2010 @ 20:50
    Seth Niemuth
    0

    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>


  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 21, 2010 @ 21:26
    Lee Kelleher
    1

    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:

    <xsl:value-of select="umbraco.library:GetMedia($mediaFolderID, 0)"/>

    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.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jan 21, 2010 @ 21:27
    Chriztian Steinmeier
    1

    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:

    <xsl:variable name="images" select="umbraco.library:GetMedia($mediaFolderID, false())" />

    OR

    <xsl:variable name="images" select="umbraco.library:GetMedia($mediaFolderID, 0)" />

    /Chriztian 

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jan 21, 2010 @ 21:28
    Chriztian Steinmeier
    0

    Darn it Lee - too quick you are :-)

    /Chriztian

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 21, 2010 @ 21:30
    Lee Kelleher
    0

    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

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jan 21, 2010 @ 21:36
    Chriztian Steinmeier
    0

    Yeah - borders on the unbearable :-)

    Good thinking with the Wiki - gotta have the cut 'n paste origins clean :-)

    /Chriztian

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Jan 22, 2010 @ 11:27
    Morten Bock
    0

    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

     

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Jan 22, 2010 @ 11:30
    Morten Bock
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft