0
votes

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

1 Answers

1
votes

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.