Question

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?

Was it helpful?

Solution

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}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top