Retrieving a list of media in umbraco
Question
I'm just starting to play with the XSLT system in umbraco where I was hoping to produce a macro which listed all the media under a specific media directory. I have come across umbraco.library:GetMedia but, frankly, I have no idea what to pass to it in order to get a list of items. The API docs at http://umbraco.org/apiDocs/html/M_umbraco_library_GetMedia.htm seem to suggest that what I probably want is to look up a node (how?) and then pass it in with
umbraco.library:GetMedia(<some node id>, true)
How would I go about getting that initial node id?
Subsequently would something like this work?
<xsl:for-each select="umbraco.library:GetMedia(<SOMEMAGIC>, 'true')">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
Solution 2
Thanks to some great help from the folks over at in the umbraco forums I figured it out. The thread is here and the solution is basically this XSLT
<xsl:for-each select="umbraco.library:GetMedia($currentPage/data [@alias='mediaDir'], 'true')/node">
<li>
<xsl:choose>
<xsl:when test="umbraco.library:GetMedia(@id, 'false')/data [@alias = 'umbracoFile']">
<a><xsl:attribute name="href">
<xsl:value-of select="umbraco.library:GetMedia(@id, 'false')/data [@alias = 'umbracoFile']"/>
</xsl:attribute>
<xsl:value-of select="@nodeName"/>
</a>
</xsl:when>
<xsl:otherwise>
<!--Do something with the directory-->
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:for-each>
coupled with a media picker control on the page.
OTHER TIPS
Here's the same code but updated to work with Umbraco 4.5 or later:
<xsl:variable name="images" select="umbraco.library:GetMedia($currentPage/mediaDir, 1)" />
<xsl:for-each select="$images/*">
<li>
<xsl:choose>
<xsl:when test="string(local-name()) = 'Image'">
<a>
<xsl:attribute name="href">
<xsl:value-of select="./umbracoFile"/>
</xsl:attribute>
<xsl:value-of select="@nodeName"/>
</a>
</xsl:when>
<xsl:otherwise>
<!--Do something with the directory-->
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:for-each>