SilverStripe 3.1:仅显示具有当前或未来日期的数据对象
SilverStripe 3.1: Only display dataobjects with a current or future date
我有演出日期。这些的简短列表显示在主页上。我如何对其进行编码以仅显示当前和未来的演出日期而忽略过去的日期?
我找到了这个例子,但到目前为止它还没有用,所以我可能没有正确应用它。 https://www.silverstripe.org/community/forums/data-model-questions/show/14451
或者有没有办法在模板中做到这一点?
HomePage.ss
<% loop $Projects.limit(1) %>
<% loop $Entrys.limit(10) %>
<li class="tourdate"><strong>$EntryDate.ShortMonth
$EntryDate.DayOfMonth</strong> - $Location</li>
<% end_loop %>
<% end_loop %>
ProjectPage.php
private static $has_many = array(
'Entrys' => 'Entry'
);
Entry.php 过时
'EntryDate' => ‘Date'
您可以使用 EntryDate.InPast()
,像这样:
<% loop $Projects.limit(1) %>
<% loop $Entrys.limit(10) %>
<% if not EntryDate.InPast() %>
<li class="tourdate"><strong>$EntryDate.ShortMonth
$EntryDate.DayOfMonth</strong> - $Location
</li>
<% en_if %>
<% end_loop %>
<% end_loop %>
我还没有测试过这个具体的例子,所以你可能需要稍微调整一下。
此外,我更希望在 Class 级别使用类似 getUpcomingShows()
的方法处理此类逻辑,该方法 return 多个对象(动态或静态limit) 的日期在现在或之后。
希望对您有所帮助:)
我有演出日期。这些的简短列表显示在主页上。我如何对其进行编码以仅显示当前和未来的演出日期而忽略过去的日期?
我找到了这个例子,但到目前为止它还没有用,所以我可能没有正确应用它。 https://www.silverstripe.org/community/forums/data-model-questions/show/14451 或者有没有办法在模板中做到这一点?
HomePage.ss
<% loop $Projects.limit(1) %>
<% loop $Entrys.limit(10) %>
<li class="tourdate"><strong>$EntryDate.ShortMonth
$EntryDate.DayOfMonth</strong> - $Location</li>
<% end_loop %>
<% end_loop %>
ProjectPage.php
private static $has_many = array(
'Entrys' => 'Entry'
);
Entry.php 过时
'EntryDate' => ‘Date'
您可以使用 EntryDate.InPast()
,像这样:
<% loop $Projects.limit(1) %>
<% loop $Entrys.limit(10) %>
<% if not EntryDate.InPast() %>
<li class="tourdate"><strong>$EntryDate.ShortMonth
$EntryDate.DayOfMonth</strong> - $Location
</li>
<% en_if %>
<% end_loop %>
<% end_loop %>
我还没有测试过这个具体的例子,所以你可能需要稍微调整一下。
此外,我更希望在 Class 级别使用类似 getUpcomingShows()
的方法处理此类逻辑,该方法 return 多个对象(动态或静态limit) 的日期在现在或之后。
希望对您有所帮助:)