[英]Smarty prints a WHITE SPACE between variables (in Loop)?
Assigning from PHP: 从PHP分配:
$smarty->assign("myArrays", Array(
Array( "title" => "ABC", "whatever" => 45),
Array( "title" => "DEF", "whatever" => 78)
));
In Smarty (v3.1.16) .tpl
file: 在Smarty(v3.1.16)
.tpl
文件中:
{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? 以及如何解决呢?
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}
: 或使用smarty指令巧妙地删除空格:
{strip}/{strip}
:
{strip}
{foreach from=$myArrays item=currentItem}
{$seperator}{$currentItem.title}{$seperator}{/foreach}
{/foreach}
{/strip}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.