Thanks Sam,
Very helpful (and fast!)
Paul
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Thanks Sam,
Very helpful (and fast!)
Paul
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.
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
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?
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 %>.
Haha...how easy it all seems when someone points it out!
thanks aram, that cracked it.......
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
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 %>