2014-02-22 32 views
0

從PHP分配:Smarty在變量之間打印WHITE SPACE(在循環中)?

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

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

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

則輸出爲:

|ABC| |DEF| 

.. WITH A「SPACE 「介於之間。
而我認爲這只是在這樣的LOOPS。

這是爲什麼?
請問該如何解決?

回答

4

使用在循環中沒有空格:

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

,或者使用Smarty的指令,使智者刪除空格:{strip}/{strip}

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

它的工作!但嚴重的是,爲什麼這麼好呢? :S顯然它就像一個BUG,因爲沒有人會喜歡有額外的空白空間而不需要它。 –

+0

不是沒有錯誤,html空間是相關的(在文本中),請閱讀我鏈接的文檔(「strip」)(特別是strip條指令的鏈接文檔)。 – 2014-02-22 09:44:54

+0

:好的.......... –