homepage Welcome to WebmasterWorld Guest from 54.166.128.254
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Smarty Templates help
CSV into rows
lasko

10+ Year Member



 
Msg#: 3440727 posted 1:32 pm on Sep 4, 2007 (gmt 0)

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

 

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3440727 posted 2:16 pm on Sep 4, 2007 (gmt 0)

>> 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;

joelgreen

5+ Year Member



 
Msg#: 3440727 posted 3:41 pm on Sep 4, 2007 (gmt 0)

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}

lasko

10+ Year Member



 
Msg#: 3440727 posted 3:50 pm on Sep 4, 2007 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved