[英]Datediff on View global:custom-text
I have a view that has "Published date" as a hidden field.我有一个将“发布日期”作为隐藏字段的视图。 I want to show a
我想展示一个
tag when the difference between current date and published date is <=3 then show a当当前日期和发布日期之间的差异为 <=3 时标记,然后显示
tag with some content.带有一些内容的标签。 So I tried the below code in a global:custom-text field :
所以我在global:custom-text 字段中尝试了以下代码:
{% if diff(date({{ now|date("m/d/Y") }}),date({{ published_at|date("m/d/Y") }})) <=3) %}
<div class="classa">
<div class="classb">
{{ field_file }}{{ field_link }} {{ field_other }} <p>New!</p>
</div>
{% else %}
<div class="classb">
{{ field_file }}{{ field_link }} {{ field_other }} <p>Old!</p>
</div>
</div>
{% endif %}
This code is not working.此代码不起作用。 Basically "difference" is not working.
基本上“差异”不起作用。 Any help to fix this issue?
任何帮助解决这个问题? Thanks
谢谢
If you want to use this inside the template and don't want to extend twig
then u can make use of DateTime.diff
which returns a DateInterval
object如果您想在模板中使用它并且不想扩展
twig
,那么您可以使用DateTime.diff
它返回一个DateInterval
对象
{% if date("NOW").diff(date(published_at)).d <= 3 %}
Output
{% endif %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.