0

Using Umbraco 7.2, I have a document type 'ResourcePage' which holds a multiple media picker property named 'folderlist'. I have placed an xslt macro named 'DisplayResourceItem' in a richtext editor property named 'resourcecontent'. The macro takes a content picker parameter, named 'resourceNodeId', which is attached in each ResourcePage when I add the macro.

My ResourcePage template references the richtext editor content, as:

<umbraco:Item field='resourcecontent' runat='server'></umbraco:Item>

Following a number of examples on https://our.umbraco.org/forum and this site, I have attempted to make a list of the files in the folderlist multiple media picker. For some reason, my best attempts give me nothing but a single string - a comma separated list of the nodeIDs of the media.

Relevant code:

<xsl:param name="currentPage"/> 
<xsl:variable name="resourceNodeId" select="/macro/resourceNodeId"/>

<xsl:template match="/">
<xsl:if test="count($resourceNodeId) &gt; 0">
    <xsl:variable name="contentfolder" select="$currentPage/folderlist"/>
    <xsl:value-of select="$contentfolder"/>
</xsl:if>

returns a list on the page "1104,1106,1111,1079,1114" (which are all the nodeIDs of the media in folderlist), but any of my attempted uses of GetMedia returns an xslt error.

Example:

<xsl:value-of select="umbraco.library:GetMedia($contentfolder, true())"/>

returns "Error parsing XSLT file: \xslt\displayResourceItems.xslt "

I will return later and show my previous attempts to display files (which worked off referencing the root Media node, and then checking if the Media folder was the same name as the ResourcePage name, which worked - but I don't want admins to have to upload in the media folder AND make sure there is a corresponding folder in the Content section).

Does anyone have any ideas? Thanks in advance.

1 Answers1

1

You can loop trought the media id's with a split and a for-each something like this:

contentfolder is a string with value "1104,1106,1111,1079,1114" the output of a multiple media picker

<xsl:variable name="linkidlijst1" select="$contentfolder" />
<ul class="img-list">

  <xsl:variable name="nodeIds" select="umbraco.library:Split($linkidlijst1, ',')" />
  <xsl:for-each select="$nodeIds/value">
    <li>
      <xsl:variable name="medianummer" select="." />
      <xsl:if test="$medianummer != ''">
        <xsl:variable name="media" select="umbraco.library:GetMedia($medianummer, 'false')" />
        <xsl:if test="$media">
          <xsl:variable name="url" select="$media/umbracoFile" />
          <xsl:variable name="width" select="$media/umbracoWidth" />
          <xsl:variable name="height" select="$media/umbracoHeight" />
          <xsl:variable name="alt" select="umbraco.library:GetMedia($medianummer, 'false')/@nodeName" />
          <xsl:if test="$url != ''">
            <img src="{$url}" alt="{$alt}" width="{$width}" height="{$height}" />
          </xsl:if>
        </xsl:if>
      </xsl:if>
    </li>
  </xsl:for-each>
</ul>

But why are you using xslt with Umbraco 7.2. Xslt is outdated. Better to use Razor in Umbraco 7.

Jan Bluemink
  • 3,467
  • 1
  • 21
  • 35
  • Sorry for the late update; I did indeed do something like this before you answered. Overall, I was just confused by the need to split the list - I'd assumed there was some method of getting a list that wasn't comma separated - something I could loop through immediately. I guessed and tried to implement the solution from http://stackoverflow.com/a/22220297/2953322 The reason I was using Xslt was that we haven't made the jump to full MVC, and I have very little knowledge of Razor (as do most of the developers around me); we sort of get the Xslt stuff! – Mahendran Nadesan Apr 14 '15 at 09:53