3212 Posts in 847 Topics by 809 members
| Go to End | ||
| Author | Topic: | 5622 Views |
-
Re: How to insert code after every third item?

2 March 2009 at 11:53am
Thanks Sam,
Very helpful (and fast!)
Paul
-
Re: How to insert code after every third item?

2 March 2009 at 12:04pm
Yeah I've hooked the forum's RSS feed into http://notify.me so that I get IM notifications of posts; it can be slightly overwhelming at times but it makes sure that I have my finger on the pulse of the forum a little more.
-
Re: How to insert code after every third item?

2 March 2009 at 11:25pm
Thanks a lot, worked like a charm.
To insert the clearing div after every third item i had to add 1 to iteratorPos (since it starts on 0), so my function ended up as
function newShelf() {
return ((($this->iteratorPos + 1) % 3) == 0);
}/jens
-
Re: How to insert code after every third item?

4 March 2009 at 6:27pm
Hi, I'm trying to use this with UncleCheeses DataObjectManager to put a clearer div after every fourth iteration, but having the same trouble where inside the control loop I cant access the newShelf function. This is what I've got:
In PeoplePage.ss
<% if People %>
<% control People %><div class="PersonPod">
<div class="PersonImage">$PersonPic.SetWidth(130)</div>
<div class="PersonName">$PersonName</div>
<div class="PersonTitle">$PersonTitle</div>
</div>
<% if newShelf %>
<div class="clearer">output this</div>
<% end_if %>
<% end_control %>
<% end_if %>Inside the PeoplePage class:
function newShelf() {
return ((($this->iteratorPos + 1) % 4) == 0);
}I've tried outputting $iteratorPos directly in the page template and that works, but no output of newShelf inside the control loop. Any ideas?
-
Re: How to insert code after every third item?

5 March 2009 at 3:34am
Hi Tsunami
You need to put your newShelf() function inside your People model class. IT makes ense if you think about it because what the <% control People %> is doing is essentailly putting you in the context of those DataObjects so any functions you call from within that control need to be available from within that object.
Just for completeness if you wanted to step out of that control block to access something on the top level page controller/model then you could use the $Top variable by calling $Top.FunctionName. As far as I can tell this doesn't work in controllers though so you couldn't do <% control top.FunctionName %>. -
Re: How to insert code after every third item?

5 March 2009 at 9:09am
Haha...how easy it all seems when someone points it out!
thanks aram, that cracked it.......
-
Re: How to insert code after every third item?

2 May 2009 at 9:39am
Can we use a similar logic for Menu iteration? I would rather not subclass the Menu, since I don't control its creation. I am making a simple footer nav, and would like to do something like
<% control Menu(1) %>
<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode">$MenuTitle</a>
<% if Iterator.peekNext %>
|
<% end_if %>
</li><% end_control %>
To no avail. Also tried Children.Iterator.peekNext
I get "Call to undefined method DataObjectSet_Iterator::cachedCall()"
... this is a common task, isn't it? Is there a better way?
thanks,
Artyom -
Re: How to insert code after every third item?

4 June 2009 at 12:53am
Artyom, i think you may use code like this:
<% control Menu(1) %>
<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode">$MenuTitle</a>
<% if Last %>
<% else %> |
<% end_if %>
</li>
<% end_control %>
| 5622 Views | ||
| Go to Top |






