Smarty在变量之间(在循环中)打印白色空格吗? [英] Smarty prints a WHITE SPACE between variables (in Loop)?

查看:80
本文介绍了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}

这篇关于Smarty在变量之间(在循环中)打印白色空格吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆