Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate smarty variable with foreach

Tags:

smarty

In a .tpl file, I'm using a smarty foreach to concatenate values from an array, separated by pipes "|" :

{foreach from=$attachments item=attachment}{$attachment.file}|{/foreach}

This writes : test1.mp3|test2.mp3|test3.mp3|

Now... I need to pass this result as a variable in an href link. The problem is I can't include my foreach inside the a href tag.

Also I tried to assign this result to a new smarty variable but can't figure how to do it.

Any help would be great. Thanks.

like image 412
Emmanuel Avatar asked Dec 22 '25 01:12

Emmanuel


1 Answers

You can do it this way:

{assign var=result value=''}
{foreach from=$attachments item=attachment}
    {assign var=temp value=$attachment.file}
    {assign var=result value=$result$temp|}
{/foreach}
like image 169
Eugene Avatar answered Dec 24 '25 10:12

Eugene



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!