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 >= 800]" />
So the "name" field for Media is @nodeName just like for Content.
The folder itself is available just as $mediaRoot.
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:
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 :-)
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.
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
the only thing that came close was
that selected the folder but did not select the children nor did
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?
Hi Rob,
First thing we need to ensure is that
GetMedia($nodeId, false())
will return only a single media node - you need to sendtrue()
as the second argument, to get the descendants too. With that out of the way, here's a couple of samples: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
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
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 ImageType1But, 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:
Hope that was better help :-)
/Chriztian
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.
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
is working on a reply...