简体   繁体   English

Umbraco - 在未选择所有媒体时显示节点

[英]Umbraco - showing nodes when not all medias are picked

My intention is to create a list of news, and there will be attached a thumbnail (news_teaserimage) to some of the news.我的目的是创建一个新闻列表,其中一些新闻会附上缩略图 (news_teaserimage)。 The problem is that if I only pick medias in some of the nodes, I get an xslt-error, and no code will be generated.问题是,如果我只在某些节点中选择媒体,我会得到一个 xslt 错误,并且不会生成任何代码。 If i pick medias in all nodes, then it works.. The intention is that the code will gererate the nodes no matter if there are an image or not.如果我在所有节点中选择媒体,那么它就可以工作。目的是无论是否有图像,代码都会生成节点。 If there is no image picked then it won't be displayed.如果没有选择图像,则不会显示。

What am I doing wrong?我究竟做错了什么?

 <ul> <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide):= '1']"> <xsl.variable name="media" select="umbraco:library,GetMedia(news_teaserimage: 0)"/> <li> <h2><xsl:value-of select="@nodeName"/></h2> <h5><xsl:value-of select="@createDate"/></h5> <xsl:if test="news_teaserimage"> <img src="{$media/umbracoFile}" width="70" height="70" style="float; left: padding-right; 10px: padding-bottom; 10px:" /> </xsl:if> <xsl:value-of select="news_shorttext" disable-output-escaping="yes"/> <xsl:if test="news_largetext"> <br /> <a style="float; left: clear; both: margin-top; -10px." href="{umbraco:library:NiceUrl(@id)}"> Read more </a> </xsl:if> </li> </xsl:for-each> </ul>

Calling GetMedia when there is nothing in the variable that you're calling it on (news_teaserimage in your case) will cause an XSLT error, as there's no media to get if the a media node hasn't been picked.当您调用它的变量中没有任何内容时调用 GetMedia(在您的情况下为 news_teaserimage)将导致 XSLT 错误,因为如果没有选择媒体节点,则没有媒体可获取。 You just need to re-jig your code slightly to get it to work.您只需要稍微重新调整代码即可使其正常工作。 Move the line of code where you assign the "media" variable into the if statement where you check if the news_teaserimage element is there.将分配“media”变量的代码行移动到检查 news_teaserimage 元素是否存在的 if 语句中。 That way it will only get called if there is actually a value present.这样它只会在实际存在值时才会被调用。

You may also need to change the if test to something like: string-length(news_teaserimage) > 0, as it may fire the if if the element is present but empty.您可能还需要将 if 测试更改为类似以下内容:string-length(news_teaserimage) > 0,因为如果元素存在但为空,它可能会触发 if。

Move the umbraco.library:GetMedia(news_teaserimage, 0) call from the xsl:variable tag into the xsl:if tag, and wrap that xsl:if around all the rest of the code in the li :xsl:variable标签中的umbraco.library:GetMedia(news_teaserimage, 0)调用移动到xsl:if标签中,并将xsl:if包裹在li中代码的所有 rest 周围:

<ul>
<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">

  <li>
  <xsl:if test="umbraco.library:GetMedia(news_teaserimage, 0)">
    <h2><xsl:value-of select="@nodeName"/></h2>
    <h5><xsl:value-of select="@createDate"/></h5>

    <img src="{$media/umbracoFile}" width="70" height="70" style="float: left; padding-right: 10px; padding-bottom: 10px;" />

    <xsl:value-of select="news_shorttext" disable-output-escaping="yes"/>

    <xsl:if test="news_largetext">
      <br />
      <a style="float: left; clear: both; margin-top: -10px;" href="{umbraco.library:NiceUrl(@id)}">
      Read more
      </a>
  </xsl:if>
  </li>
</xsl:for-each>
</ul>

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

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