Forum Moderators: coopster
Can someone point me into the right direction please, very new to Smarty.
I have a Variable
$var = "A,B,C"; //stored in DB
in my template I want the designer of the template to decide when to list the data in rows like
<td>A,</td>
<td>B,</td>
<td>C</td>
Can this be done without the php code?
I will have content in a database and I won't know if the designer wants to make a particular field into a list.
Cheers
Not that I know of. It should be as easy as an explode and then implode to get the desired look. Something like this:
$parts = [url=http://www.php.net/explode]explode[/url](',',$string_from_db);
$string = '<td>'.[url=http://www.php.net/implode]implode[/url]('</td><td>',$parts).'</td>';
echo $string;
in php build array
$ItemsList = explode(... like shown above)
$smarty->assign('ItemsList',$ItemsList);
in template designer does
{foreach name=ItemsList from=$ItemsList item=i}
<td>{$i}</td>
{/foreach}
or just
{foreach name=ItemsList from=$ItemsList item=i}
{$i}
{/foreach}
Joelgreen thats what I've ended up doing.
Made the variables into arrays and give the designer the choice to make lists.
I've experimented with the {foreach} and put the following
{if $smarty.foreach.NAME.first}FIRST ROW TEXT = {/if}
>> {$value}
So I now get
FIRST ROW TEXT >> row1
>> row2
>> row3
Cheers