检索 umbraco 中的媒体列表

发布于 2024-08-05 02:42:41 字数 771 浏览 1 评论 0原文

我刚刚开始使用 umbraco 中的 XSLT 系统,我希望生成一个宏,列出特定媒体目录下的所有媒体。我遇到过 umbraco.library:GetMedia 但坦率地说,我不知道要传递给它什么才能获取项目列表。 API 文档位于 http://umbraco.org/apiDocs/html/M_umbraco_library_GetMedia.htm 似乎表明我可能想要的是查找一个节点(如何?),然后将其传递给

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

How would I go about getting that initial node id?

随后类似这样的事情会起作用吗?

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看海 2024-08-12 02:42:41

以下是相同的代码,但已更新以适用于 Umbraco 4.5 或更高版本:

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

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>
心凉怎暖 2024-08-12 02:42:41

感谢 umbraco 论坛上的人们的大力帮助,我找到了答案。该线程位于此处解决方案基本上是将该 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>

与页面上的媒体选择器控件相结合。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文