用 'and' 结束一个聪明的 foreach 循环

Ending a smarty foreach loop with 'and'

我正在从数组中提取姓名和日期列表,我想将其呈现为自然语言句子,倒数第二项后跟 'and',然后是最后一项。

这是我的代码:

<p>In the past, we&rsquo;ve interviewed the likes of {foreach from=$interviewees key=k item=v name=people}
<a href="https://www.example.com/interviews/{$v}.html">{$k}</a
{if $smarty.foreach.people.last}. {else},{/if} {foreachelse}{/foreach}

其中key是人名,item是日期形式的url(201509)。这会输出一个漂亮的逗号分隔列表,但我如何插入一个自然的外观并完成列表?

我希望得到以下输出:

<p>In the past, we&rsquo;ve interviewed the likes of 
<a href="https://www.example.com/interviews/201405.html">Forename Surname</a>,  
<a href="https://www.example.com/interviews/201408.html">Forename Surname</a>,  
<a href="https://www.example.com/interviews/201403.html">Forename Surname</a> 
and  <a href="https://www.example.com/interviews/201312.html">Forename Surname</a>.

感谢您的帮助!

试试这个:

<p>In the past, we&rsquo;ve interviewed the likes of {foreach     
from=$interviewees key=k item=v name=people}
{if $smarty.foreach.people.last} and {/if}
<a href="https://www.example.com/interviews/{$v}.html">{$k}</a>
{if $smarty.foreach.people.last}.{else}
   {if $smarty.foreach.people.iteration+1!=$smarty.foreach.people.total},{/if}  
{/if} {foreachelse}{/foreach}