Getting a list of media in umbraco

I am just getting started playing with the XSLT system in umbraco where I was hoping to create a macro that lists all the media in a specific media directory. I came across umbraco.library: GetMedia, but honestly, I have no idea what to pass to him to get the list of items. The API docs at http://umbraco.org/apiDocs/html/M_umbraco_library_GetMedia.htm seems to say that I probably want to find a node (how?) And then pass it using

umbraco.library:GetMedia(<some node id>, true)

      

How can I get this initial node id?

Will there be something like this work afterwards?

<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>

      

+2


source to share


2 answers


Thanks to a lot of help from people on the umbraco forums, I figured it out. The thread is here and the solution is basically 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>

      



combined with on-page media picker controls.

0


source


Here's the same code, but updated to work with Umbraco 4.5 or newer:



<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>

      

+1


source







All Articles