Juliet Rybets Juliet Rybets - 3 months ago 9
Smarty Question

Smarty: how to merge a result of the array in one html tag

everybody!
I have some Smarty code:

{foreach name=aussen item=data from=$data}
{assign var='model' value=$data.products_model}

<input type="hidden" name="aussen" value={$model}/>

{/foreach}


And I get result like this:

<input type="hidden" name="aussen" value="5001"/>
<input type="hidden" name="aussen" value="5002"/>


But I want to get something like this:

<input type="hidden" name="aussen" value="5001,5002"/>


Could somebody please help me to get this result. Thanks

Answer

Just do the foreach inside the input

<input type="hidden" name="aussen" value="
{foreach $data as $item}
{if !$item@first},{/if}
{$item.products_model}
{/foreach}
"/>

{/foreach}

Comments