Page 1 of 1
Not directly S9Y... but probably Smarty
Posted: Thu Oct 05, 2006 1:51 pm
by mastergaurav
Hi,
I am trying to emit out a google ad only on the last entry on the page.
I am trying to use the code as follows:
{if $smarty.foreach.dategroup.last}
.... Place google-adsense-code ....
{/if}
However, I am getting ad on all the entries.
Am I doing something wrong?
Cheers,
Gaurav
Re: Not directly S9Y... but probably Smarty
Posted: Thu Oct 05, 2006 2:57 pm
by garvinhicking
Hi!
I think you are looking on the wrong, inner smarty foreach loop. There are two nested loops, you need to check the outer one, because the inner one would return "last" multiple times.
The outer loop is for all entries of the page, the inner loop for all entries of a single date on the page.
HTH,
Garvin
Re: Not directly S9Y... but probably Smarty
Posted: Thu Oct 05, 2006 6:59 pm
by mastergaurav
garvinhicking wrote:I think you are looking on the wrong, inner smarty foreach loop.
I had it on the outer loop:
{foreach from=$entries item="dategroup"}
<div class="serendipity_Entry_Date">
{if $dategroup.is_sticky}
<h3 class="serendipity_date">{$CONST.STICKY_POSTINGS}</h3>
{else}
<h3 class="serendipity_date">{$dategroup.date|@formatTime:DATE_FORMAT_ENTRY}</h3>
{/if}
{if $smarty.foreach.dategroup.first}
<!-- ADSENSE CODE HERE -->
{/if}
.........
.........
{foreach ......}
.........
.........
{/foreach}
.........
.........
{/foreach}
Cheers,
Gaurav
Re: Not directly S9Y... but probably Smarty
Posted: Fri Oct 06, 2006 11:16 am
by garvinhicking
Hi!
You must assign a name to the loop!
Code: Select all
{foreach name="outerloop" from=$entries item="dategroup"}
HTH,
Garvin
Re: Not directly S9Y... but probably Smarty
Posted: Sat Oct 07, 2006 12:33 pm
by mastergaurav
You must assign a name to the loop!
Hi Garvin,
Thanks! It just works beautifully. I think I am learning Smarty pretty fast
Cheers,
Gaurav Vaish
http://www.mastergaurav.com
http://eduzine.edujinionline.com