Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Smarty Templates help

CSV into rows



1:32 pm on Sep 4, 2007 (gmt 0)

10+ Year Member


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


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.



2:16 pm on Sep 4, 2007 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

>> Can this be done without the php code?

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;


3:41 pm on Sep 4, 2007 (gmt 0)

5+ Year Member

Why don't you always pass it to smarty as list, and designer can do either

in php build array
$ItemsList = explode(... like shown above)

in template designer does

{foreach name=ItemsList from=$ItemsList item=i}

or just

{foreach name=ItemsList from=$ItemsList item=i}


3:50 pm on Sep 4, 2007 (gmt 0)

10+ Year Member

Many thanks

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

>> row2
>> row3



Featured Threads

Hot Threads This Week

Hot Threads This Month