简体   繁体   English

调试多个媒体选择器umbraco xslt宏

[英]Debugging multiple media picker umbraco xslt macro

Using Umbraco 7.2, I have a document type 'ResourcePage' which holds a multiple media picker property named 'folderlist'. 使用Umbraco 7.2,我有一个文档类型“ ResourcePage”,其中包含一个名为“ folderlist”的多媒体选择器属性。 I have placed an xslt macro named 'DisplayResourceItem' in a richtext editor property named 'resourcecontent'. 我在名为“ resourcecontent”的富文本编辑器属性中放置了一个名为“ DisplayResourceItem”的xslt宏。 The macro takes a content picker parameter, named 'resourceNodeId', which is attached in each ResourcePage when I add the macro. 宏带有一个名为“ resourceNodeId”的内容选择器参数,当我添加宏时,该参数会附加在每个ResourcePage中。

My ResourcePage template references the richtext editor content, as: 我的ResourcePage模板引用RTF编辑器的内容,如下所示:

<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. https://our.umbraco.org/forum和此站点上的许多示例之后,我试图在文件夹列表多媒体选择器中列出文件列表。 For some reason, my best attempts give me nothing but a single string - a comma separated list of the nodeIDs of the media. 出于某种原因,我的最佳尝试只给了我一个字符串-逗号分隔的媒体节点ID列表。

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. 返回页面“ 1104,1106,1111,1079,1114”上的列表(它们是folderlist中媒体的所有nodeID),但是我尝试使用GetMedia的任何尝试都会返回xslt错误。

Example: 例:

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

returns "Error parsing XSLT file: \\xslt\\displayResourceItems.xslt " 返回“解析XSLT文件时出错:\\ 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). 稍后我将返回并显示我先前的尝试显示文件的方法(该方法可以参考根Media节点,然后检查Media文件夹是否与ResourcePage名称相同,但可以,但是我不希望管理员拥有以上传到媒体文件夹中,并确保在“内容”部分中有相应的文件夹)。

Does anyone have any ideas? 有人有什么想法吗? Thanks in advance. 提前致谢。

You can loop trought the media id's with a split and a for-each something like this: 您可以使用分割和for-each这样循环遍历媒体ID:

contentfolder is a string with value "1104,1106,1111,1079,1114" the output of a multiple media picker contentfolder是一个字符串,其值为“ 1104、1106、1111、1079、1114”,是多个媒体选择器的输出

<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. 但是,为什么要在Umbraco 7.2中使用xslt。 Xslt is outdated. Xslt已过时。 Better to use Razor in Umbraco 7. 最好在Umbraco 7中使用Razor。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM