簡體   English   中英

如何顯示“新的”子頁面數Umbraco XSLT

[英]How to display “number of new” child pages Umbraco XSLT

我要嘗試合並兩個單獨的代碼段。

第一個計算子頁面的數量並顯示一個數字:

例如8個子頁面(或子頁面,如果只有1個頁面)

<xsl:choose>
<xsl:when test="count(child::DocTypeAlias) &gt; 1">
    <p><xsl:value-of select="count(child::DocTypeAlias)"/> child pages</p>
</xsl:when>
<xsl:otherwise>
    <p><xsl:value-of select="count(child::DocTypeAlias)"/> child page</p>
</xsl:otherwise>

該代碼檢測頁面是否在最近30天內創建:

<xsl:variable name="datediff" select="umbraco.library:DateDiff(umbraco.library:ShortDate(umbraco.library:CurrentDate()), umbraco.library:ShortDate(@createDate), 'm')" />
    <xsl:if test="$datediff &lt; (1440 * 30)">
        <p>New</p>
    </xsl:if>

我想將它們結合起來,這樣我就可以得到一個子頁面數和一個“新”頁面數。

例如8個子頁面-2個新頁面

我嘗試了以下操作,但未返回正確的值:

<xsl:variable name="datediff" select="umbraco.library:DateDiff(umbraco.library:ShortDate(umbraco.library:CurrentDate()), umbraco.library:ShortDate(@createDate), 'm')" />
    <xsl:choose>
        <xsl:when test="$datediff &lt; (1440 * 30) and count(child::DocTypeAlias) &gt; 1">
            <p><xsl:value-of select="$datediff &lt; (1440 * 30) and count(child::DocTypeAlias)"/> new pages</p>
        </xsl:when>
        <xsl:otherwise>
            <p><xsl:value-of select="$datediff &lt; (1440 * 30) and count(child::DocTypeAlias)"/> new page</p>
        </xsl:otherwise>
    </xsl:choose>

它返回:“真實的新頁面”我不知道如何顯示該數字(2個新頁面)。

有人可以幫忙嗎? 歡呼聲,合資企業

仔細查看您為該段指定的內容:

<p>
  <xsl:value-of select="
    $datediff &lt; (1440 * 30) 
    and 
    count(child::DocTypeAlias)"/> 
  new pages
</p>

您有一個and ,布爾值為左參數,整數為右參數。 投入處理器的步伐:看起來不像您在要求它計算布爾值嗎?

由於此表達式包含在已經測試過日期差的when元素中,因此您(幾乎可以肯定)不需要重復$ datediff與43200的比較。(我說“幾乎可以肯定”,因為我認為我不會詳細了解您的應用程序的邏輯,所以我可能是錯的。)我懷疑您想說的是:

<p>
  <xsl:value-of select="count(child::DocTypeAlias)"/> 
  new pages
</p>

你需要在類似的變化otherwise

非常感謝Chriztian Steinmeier:

 <!-- The date calculation stuff -->
<xsl:variable name="today" select="umb:CurrentDate()" />
<xsl:variable name="oneMonthAgo" select="umb:DateAdd($today, 'm', -1)" />

<!-- Grab the nodes to look at -->
<xsl:variable name="nodes" select="$currentPage/DocTypeAlias" />

<!-- Pages created within the last 30 days -->
<xsl:variable name="newPages" select="$nodes[umb:DateGreaterThanOrEqual(@createDate, $oneMonthAgo)]" />
<xsl:template match="/">
  <xsl:choose>
    <xsl:when test="count($newPages)">
      <p> <xsl:value-of select="count($newPages)" /> <xsl:text> New Page</xsl:text>
        <xsl:if test="count($newPages) &gt; 1">s</xsl:if>
      </p>
    </xsl:when>
    <xsl:otherwise>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM