Section循环以错误的索引/值开始

问题描述 投票:0回答:1

我想填写出生年份的选择框,从当前年份-18开始,然后向后100年。不知怎的,循环开始于2000而不是2001。

当我使用smarty.now功能并从中减去18年时,它将导致2001年是正确的。

但是当我在一个section循环和步骤-1中使用相同的函数时,循环将从2000而不是2001开始。

我可以在section循环中使用-17,但是我想知道为什么这里的偏移量似乎是1,即使start的默认值是0,根据文档。

{$smarty.now|date_format:"%Y"-18}
{*  Result is 2001 as expected *}
<br>
{section name=bar loop=$smarty.now|date_format:"%Y"-18 max=100 step=-1}
{$smarty.section.bar.index}
{/section}
{*  Loop starts with 2000,1999... why? *}
smarty
1个回答
1
投票

这是因为在你的date_format,你把step = -1

Smarty在显示第一个值之前在该部分中执行此步骤。所以,该部分将是这样的:

2000 1999 1998 ..

© www.soinside.com 2019 - 2024. All rights reserved.