Re: [SMARTY] sections

From: Date: Sat, 13 Dec 2003 17:49:14 +0000
Subject: Re: [SMARTY] sections
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10686@lists.php.net to get a copy of this message
Another solution would be changing your data to something like $news['2003-12-12'][0]['headline'] = "news01" ; $news['2003-12-12'][1]['headline'] = "news02" ; $news['2003-12-13'][1]['headline'] = "news01" ; And then in the smarty side {foreach key=date item=items from=$news} Date: $date<br> <blockquote> {section name=t loop=$items} headline: $items[t].headline<br> {/section} </blockquote> {/foreach} Regards, Tiago S Daitx Jason Hubble wrote:
Franco,
I made a section to loop some news, but i want the date as header and if
the
second news has the same date it should not be displayed twice. I made it like this: <table> {assign var="lastdate" value="0"} {section name=Index loop=$news} {if $news[Index].date ne $lastdate}
       <TR><td>{$news[Index].date}</td></tr>
{/if}
       <tr><Td>{$news[Index].headline}</td></tr>
       {assign var="lastdate" value=$news[Index].date}
{/section} </table> But like this I must use a second var. My question now is, is there a way
to
do the same without using a second var. somthing like: {if $news[Index].date ne $news[Index-1].date]} but this does not work.
The best way to solve your problem would be to change your data structure in PHP to something like this: $news[0]['date']= "2003-12-12"; $news[0]['items'][0]['headline'] = "news"; $news[0]['items'][1]['headline']] = "news"; $news[1]['date']= "2003-12-13"; $news[1]['items'][0]['headline'] = "news"; Once you've done that, you could have nested sections like this: {section name=i loop=$news} Date: $news[i].date<br /> <blockquote> {section name=t loop=$news[i].items} headline: $news[i].items[t].headline<br /> {/section} </blockquote> {/section} Jason


« previous php.smarty.general (#10686) next »