Re: [SMARTY] sections

From: Date: Sat, 13 Dec 2003 13:48:55 +0000
Subject: Re: [SMARTY] sections
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10685@lists.php.net to get a copy of this message
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 (#10685) next »