List all media children (folders) from a media id - old scheme
Hi all,
I'm in a situation where I have to make a list of all media children folders of a specificed media folder using XSLT. The challenge for me is, that this umbraco solution is running 4.0.4.2 - the old XSLT scheme which I'm clueless about :/
The $currentPage has got a mediapicker datatype which points to the root media folder, so I've found that I can get the id from that like this:
O.k it seemed to be a 'bug' in the old scheme, I just hit "Skip testing" and everything is running just as expected! ;) Now I just need to exclude a certain folder and I'm all set!
<!-- The value of mediaFolder is an XML snippet, where we need to select the id attribute from the XML node <node> --> <xsl:param name="mediaFolderID" select="$mediaFolder/node/@id" />
<!-- For each XML node <node> where the nodeTypeAlias attribute = Folder --> <xsl:for-each select="$files//node [@nodeTypeAlias ='Folder']"> <!-- Do stuff here --> </xsl:for-each>
</xsl:template>
The mediaFolder is a parameter in the macro so I can select which media folder I want it to start at.
Actually, the "Save" thing is not a "bug" per se - it's because Umbraco tries to run the transform to verify the validty of the XSLT, but it doesn't put values in the macro parameters so depending on how your code is set up, it calls GetMedia() with no @id...
Anyways, here's a way to use real XSLT to do what you want to do - commented to help, but ask away if there's something you'd like to know about:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<xsl:template match="/">
<!-- Process the 'galleri' property if it has a value -->
<xsl:apply-templates select="$currentPage/data[@alias = 'galleri'][normalize-space()]" mode="media.all" />
</xsl:template>
<!-- Template for media that needs fetching - handles potential error -->
<xsl:template match="*" mode="media.all">
<xsl:variable name="mediaNode" select="umb:GetMedia(., true())" />
<xsl:apply-templates select="$mediaNode[not(error)]" />
</xsl:template>
<!-- Template for a Media Folder -->
<xsl:template match="node[@nodeTypeAlias = 'Folder']">
<ul>
<xsl:apply-templates select="node[@nodeTypeAlias = 'Image']" />
</ul>
</xsl:template>
<!-- Template for a Media Image -->
<xsl:template match="node[@nodeTypeAlias = 'Image']">
<li>
<a href="{data[@alias = 'umbracoFile']}">
<xsl:value-of select="@nodeName" />
</a>
</li>
</xsl:template>
<!-- Exclude a specific Folder -->
<xsl:template match="node[@nodeTypeAlias = 'Folder'][@nodeName = 'Word files']" />
<!-- - or a specific File/Image -->
<xsl:template match="node[@nodeTypeAlias = 'Image'][@nodeName = 'My 80s hair style']" />
</xsl:stylesheet>
List all media children (folders) from a media id - old scheme
Hi all,
I'm in a situation where I have to make a list of all media children folders of a specificed media folder using XSLT. The challenge for me is, that this umbraco solution is running 4.0.4.2 - the old XSLT scheme which I'm clueless about :/
The $currentPage has got a mediapicker datatype which points to the root media folder, so I've found that I can get the id from that like this:
The above returns the root folder id as expected, but I honestly haven't got a clue how to list the children folders of this.
Anyone know anything about this? :)
All the best,
Bo Mortensen
Hrmm, I've tried this one aswell, it seems to make more sense to me:
However, I get the dreaded error: System.OverflowException: Value was either too large or too small for an Int32.
To me, the number($currentPage/data [@alias = 'galleri']) *should* return the id of the root folder as an integer/a numer.. ?
O.k it seemed to be a 'bug' in the old scheme, I just hit "Skip testing" and everything is running just as expected! ;) Now I just need to exclude a certain folder and I'm all set!
Bo,
Have you considered something similar to this:
The mediaFolder is a parameter in the macro so I can select which media folder I want it to start at.
--
Donald
Hi Bo,
Actually, the "Save" thing is not a "bug" per se - it's because Umbraco tries to run the transform to verify the validty of the XSLT, but it doesn't put values in the macro parameters so depending on how your code is set up, it calls GetMedia() with no @id...
Anyways, here's a way to use real XSLT to do what you want to do - commented to help, but ask away if there's something you'd like to know about:
/Chriztian
Hi Chriztian! Thanks a lot for your help :) appreciated!
It looks a lot cleaner than the XSLT I made, so i'll go with that instead :) Thanks!
is working on a reply...