Smarty prints a WHITE SPACE between variables (in Loop)?

不羁的心 提交于 2019-12-08 12:45:56

问题


Assigning from PHP:

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

In Smarty (v3.1.16) .tpl file:

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

Then it will output as:

|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?


回答1:


Use no spaces in the loop:

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

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}


来源:https://stackoverflow.com/questions/21952072/smarty-prints-a-white-space-between-variables-in-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!