Smarty在变量之间(在循环中)打印白色空格吗?

问题描述:

从PHP分配:

$smarty->assign("myArrays", Array(
                   Array( "title" => "ABC", "whatever" => 45),
                   Array( "title" => "DEF", "whatever" => 78)
               ));

在Smarty(v3.1.16).tpl文件中:

In Smarty (v3.1.16) .tpl file:

{assign "seperator" "|"}
{foreach from=$myArrays item=currentItem}
    {$seperator}{$currentItem.title}{$seperator}
{/foreach}

然后它将输出为:

|ABC| |DEF|

.. 中间有一个空格" .
而且我认为这只是在这样的循环中.

.. WITH A "SPACE" in-between.
And i think it is only in such LOOPS.

为什么会这样?
以及如何解决呢?

Why is so?
And how to solve it please?

在循环中不使用空格:

{foreach from=$myArrays item=currentItem}{$seperator}{$currentItem.title}{$seperator}{/foreach}

或使用smarty指令巧妙地删除空格: {strip}/{strip} :

or use the smarty directive to make smarty remove spaces: {strip}/{strip}:

{strip}
    {foreach from=$myArrays item=currentItem}
        {$seperator}{$currentItem.title}{$seperator}{/foreach}
    {/foreach}
{/strip}