Page 1 of 1

Can I change the variables used in entries.tpl {foreach}

Posted: Wed Sep 06, 2006 8:53 pm
by carl_galloway
Hi all,

I'm trying to change the {foreach} loop in entries.tpl so that the first entry is ignored. The code below works well for sticky entries and where only a single entry was written on the day, but if more than one entry was written on the day then all entries for that day are ignored.

Code: Select all

{foreach name="entryloop" from=$entries
item="dategroup"}
{foreach from=$dategroup.entries item="entry"}
{if $smarty.foreach.entryloop.index==0 }
<!-- don't print -->
{else}
How would I separate out only the first entry? I've tried changing item="dategroup" to item="entry". I've also tried adding a {counter} between the foreach loops, but nothing seems to work.

Thanks, Carl

Re: Can I change the variables used in entries.tpl {foreach}

Posted: Wed Sep 06, 2006 10:00 pm
by mgroeninger
Ok, I am guessing here, but wouldn't this work:

Code: Select all

{foreach name="loop1"  from=$entries
item="dategroup"}
{foreach name="loop2" from=$dategroup.entries item="entry"}
{if $smarty.foreach.loop1.index==0 && $smarty.foreach.loop2.index==0}
<!-- don't print -->
{else}

My logic is this: You want to exclude the first post, but include all the other posts regardless of date?

So, I think you want to loop through the dates, calling the loop "loop1".

Then you loop through the entries, but let's call this something else so we don't get confused, like "loop2".

Then we just ignore the first index result from loop2, but only if we are still in loop1 first index.

Posted: Wed Sep 06, 2006 10:03 pm
by carl_galloway
Oh Matthew, you can have my first born for that, works a treat - thank you.

Posted: Wed Sep 06, 2006 10:12 pm
by mgroeninger
*grin* I'm glad it worked, but you can keep your first born... Mine's enough to run me ragged; I'm trying not to collect anyone elses... :D