Copied to clipboard

Flag this post as spam?

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


  • rob 75 posts 170 karma points
    Sep 04, 2013 @ 16:48
    rob
    0

    XPath to Media items for Filter

    I have found some snippits of information about XPath to Media items but this seems to be something very few people are doing.

    Media
    -Product1
    --ImageType1
    ---Image1
    ---Image2
    --ImageType2
    ---Image3
    ---Image4
    -Product2
    etc ...
    

    I want an XPath that returns all the images in the ImageType1 folder and preferably the ImageType1 folder as well.

    This is for a custom data type using the Multi Node Tree Picker "XPath Filter" field.

    There are lots of examples for using the filter for Content but I can find nothing for Media.

    tried

    //Folder[@name='ImageType1']
    //Folder[@alias='ImageType1']
    //Folder[@Name='ImageType1']
    //Folder[@Alias='ImageType1']
    /descendant::Folder/*
    

    the only thing that came close was

    //Folder[@id='4765']
    

    that selected the folder but did not select the children nor did

    //Folder[@id='4765']/*
    

    FYI: the whole point of this exercise is to be node ID agnostic

    So what is the "name" field for a Media Folder?

    How do I make the XPath select all children as /* does not seem to work?

    Bonus points, how can I get not only the Image items in the selection but the folder as well?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 04, 2013 @ 17:05
    Chriztian Steinmeier
    0

    Hi Rob,

    First thing we need to ensure is that GetMedia($nodeId, false()) will return only a single media node - you need to send true() as the second argument, to get the descendants too. With that out of the way, here's a couple of samples:

    <!-- Grab a parent Folder node -->
    <xsl:variable name="mediaRoot" select="umbraco.library:GetMedia(SOME_ID, true())" />
    
    <!-- Grab all sub folders (immediate children) -->
    <xsl:variable name="subFolders" select="$mediaRoot/Folder" />
    
    <!-- Grab all folders named 'ImageType1' (at all levels) -->
    <xsl:variable name="imageType1Folders" select="$mediaRoot//Folder[@nodeName = 'ImageType1']" />
    
    <!-- Grab all images of the 'Image' type (alias) at all levels -->
    <xsl:variable name="images" select="$mediaRoot//Image" />
    
    <!-- Grab all of those images that are 800px++ wide -->
    <xsl:variable name="eightHundredPlus" select="$images[umbracoWidth &gt;= 800]" />
    

    So the "name" field for Media is @nodeName just like for Content.

    The folder itself is available just as $mediaRoot.

    Hope that helps a bit

    /Chriztian

  • rob 75 posts 170 karma points
    Sep 04, 2013 @ 18:01
    rob
    0

    Almost, the Filter did not like $mediaRoot but once removed @nodeName did get me the folder.

    But I still can not get the children.

    adding a / caused an error and /* made no difference

    pesky children

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 04, 2013 @ 22:53
    Chriztian Steinmeier
    0

    Hi Rob,

    Sorry, I totally missed that you're using the MNTP data type.

    So, from what I've been testing, you're not able to allow selecting the folder you've set as the "Start Node ID"... furthermore, it seems that the XPath is executed against a single XML node, so you can't base your filter on anything above or below the node being matched.

    However, you can do stuff like this to enable both Folders and Images for selection: Folder | Image

    You can also say: Folder[@nodeName = 'ImageType1'] | Image to enable selecting any Image and the Folder named ImageType1

    But, selecting only Images in that folder seems to not be possible, since you don't have the context - that is, when you want to be ID-agnostic. Otherwise you could say:

    Image[@parentID = 4765] | Folder[@id = 4765]
    

    Hope that was better help :-)

    /Chriztian

  • rob 75 posts 170 karma points
    Sep 05, 2013 @ 09:43
    rob
    0

    Thanks for taking the time to look into this for me. MNTP does not like

    Folder[@nodeName = 'ImageType1'] | Image (or any variant with // or white space changes)

    And it sounds like it just does not work as I expected.

    Does anyone know if DAMP has the same shortcomings?

    Luckily the project does not NEED this functionality, it was just a nice to have.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 05, 2013 @ 10:20
    Chriztian Steinmeier
    100

    That sounds very weird - I just tested those samples so I know they work with MNTP...

    DAMP is a much better experience for the editors, though a little bit different. You can customize a lot but you can only use XPath to define the start node, and then you allow extensions and/or Media Types. Different animal :-)

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft