Welcome to WebmasterWorld Guest from 54.166.122.69

Forum Moderators: coopster & jatar k

Smarty Templates help

CSV into rows

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

10+ Year Member



Hi

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

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

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ 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)
$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}

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

FIRST ROW TEXT >> row1
>> row2
>> row3

Cheers

 

Featured Threads

Hot Threads This Week

Hot Threads This Month