Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

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.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Customize Loop (in Controller)


Go to End


3 Posts   2986 Views

Avatar
spierala

Community Member, 80 Posts

14 July 2012 at 2:15am

Edited: 14/07/2012 2:18am

Hello all,
I have a Lexikon Page which displays an alphabetically ordered List. Always when the title of a listItem is starting with a new letter, then the title should be highlighted.

So I wonder how to do that. I think I have to customize the controller of the LexikonPage and override the function that is responsible for returning the LexikonItems... and then customize the objects that are returned by setting an additional property (saying highlight or not).

Thats so far my template code:

<div id="lexikon-items">
			<% loop LexikonItems %>
				<h3>$Title</h3>
				<p>$Description</p>
			<% end_loop %>
		</div>

that works so far and displays just the data as expected. But how do I have to customize the controller of LexikonPage?

I started now like this:

	public function LexikonItems(){

	}

But how do I access here the LexikonItems?

I use SS3. (A pure SS3 Forum could be nice... :))
Many thanks,
Florian

Avatar
lerni

Community Member, 81 Posts

14 July 2012 at 12:11pm

hi florian

wold this help?
http://doc.silverstripe.org/framework/en/howto/grouping-dataobjectsets/

then just add a extra class if it's the first item (<% if First %>) in the Children loop and do it per css.

lukas

Avatar
spierala

Community Member, 80 Posts

18 July 2012 at 3:33am

Hey Lukas,
thank you! that is exactly what I needed! pretty cool feature :)
Florian