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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Function Needed in ChildrenOf() Control

Go to End

4 Posts   1399 Views


Community Member, 245 Posts

29 July 2008 at 7:02am

Edited: 29/07/2008 7:03am


I am on a Grandchild level looping through my Grandparents, and I need to look at the URL's of each of them and treat one of them differently as I write them to the page. I do not know where to put the function that returns whether the URL is a certain one. Here is my structure:

Experience (ExperienceHolder, URL = "experience")
>>>News (NewHolder)
>>>Item 2
>>>Item 3
>>>Item 4

I am in the NewsPage template, using <% control ChildrenOf(experience) %>, I am writing out News, Item 2, Item 3, Item 4, etc. Now, IF it is news, then I want to write something different. So in my control loop I have <% if IsCertainItem(URLSegment) %> logic, which I am sure will work. I just don't know WHERE to put this boolean function:

function IsNewsItem($url) {
if($url=="blah-blah-blah") {
return true;
return false;

Because I am looping through the Children of Experience, of which theer are several, so it is unclear. I tried putting the function in NewsPage, ExperienceHolder, AND NewsHolder, and it is still not being called.

Any help?? I run into this confusion a lot in SilverStripe-- not knowing WHERE to put my code.

Thanks in advance,


Community Member, 473 Posts

29 July 2008 at 7:18am

why not just use

<% if URLSegment = url %>

As you'll be using that method of different page types, a good place for it would be the Page class


Community Member, 245 Posts

29 July 2008 at 7:40am


Hey, I didn't think you could do string comparisons in the SS templates! I didn't even think to try it as I have been thwarted there before.

What exactly ARE the rules of what you can't do?!




Forum Moderator, 5523 Posts

29 July 2008 at 1:12pm - has a list of things you can do in templates.