部分循环以错误的 index/value 开头

Section loop starts with wrong index/value

我想在 select 框中填写出生年份,年份从当前年份 -18 开始,然后向后 100 年。循环以某种方式从 2000 而不是 2001 开始。

当我使用 smarty.now 函数并从中减去 18 年时,结果是 2001,这是正确的。

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

我可以在节循环中使用 -17,但我想了解为什么这里似乎有 1 的偏移量,即使根据文档,开始的默认值为 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? *}

这是因为在你的 date_format 中,你输入了 step = -1 .

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

2000 1999 1998 ..