问题
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