我使用的是TYPO3 9,新闻插件(新闻系统)。
我正在寻找一种按年对新闻文章进行分组的方法,如下所示:
2019
--------
article 1
article 2
article 3
--------
2018
--------
article 1
article 2
...
我找不到一个简单的解决方案,也很难相信实现这一点的唯一方法就是编辑TYPO3的源代码……
有人能帮上忙吗?
Bernd Wilke建议的已修复且工作正常的代码:
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:n="http://typo3.org/ns/GeorgRinger/News/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:layout name="General" />
<!--
=====================
Templates/News/List.html
-->
<f:section name="content">
<!--TYPO3SEARCH_end-->
<f:if condition="{news}">
<f:then>
<f:variable name="oldYear">2010</f:variable>
<f:for each="{news}" as="newsItem" iteration="iterator">
<f:variable name="currentYear"><f:format.date format="%Y">{newsItem.datetime}</f:format.date></f:variable>
<f:if condition="{oldYear} < {currentYear}">
<hr />
<h3>{currentYear}</h3>
<hr />
</f:if>
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>
</f:then>
<f:else>
<div class="alert ">
<f:translate key="list_nonewsfound" />
</div>
</f:else>
</f:if>
<!--TYPO3SEARCH_begin-->
</f:section>
</html>
然而,我把这个问题归功于格奥尔格·林格,因为他的解决方案很快就奏效了。
发布于 2019-05-22 13:05:36
对于这样的分组,没有typoscript选项。
但你可以在FLUID中实现:
将新闻列表的模板文件复制到您的(站点)扩展中,并根据您的需要对其进行修改:构建一个组处理。
<f:variable.set name="oldYear">0000</f:variabel.set>
<f:for each="{news}" as="newsItem" iteration="iterator">
<f:variable.set name="currentYear">{newsItem.datetime->f:format.date("Y")}</f:varaible.set>
<f:if condition="{oldYear} == {currentYear}">
<hr />
<h3>{currentYear}</h3>
<hr />
<f:variable.set name="oldYear">{currentYear}</f:variable.set>
</f:if>
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>
您可以使用this answer或this answer中提到的viewhelpers之一。
https://stackoverflow.com/questions/56246296
复制相似问题