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

Variable includes

Go to End

3 Posts   1969 Views


Forum Moderator, 4102 Posts

27 October 2007 at 4:26am

Any way to do something like this?

<% include $URLSegment_sidebar %>

So I don't have to make a huge list like this?

<% if InSection(about) %>
<% include about_sidebar %>
<% end_if %>

< if InSection(news) %>
<% include news_sidebar %>
<% end_if %>

Ugh.. seems a little unnecessary.


Forum Moderator, 5523 Posts

28 October 2007 at 6:23pm

yep I believe you should be able to use $URLSegment (as long as people don't go changing the urls :P)

You might need to wrap the $URLSegment in curly braces {} so {$URLSegement}_sidebar to get it work.


Forum Moderator, 922 Posts

28 October 2007 at 8:44pm

Edited: 28/10/2007 8:45pm

Usually it's not a generally safe idea to look for templates by a $URLSegment value in it, as it's far too dynamic - especially when you're giving the site to a client who could change page names, interrupting the $URLSegment value.

And, AFAIK, there's currently no way to set in stone the page URLSegment value. A good reason to not is it's generally good SEO to make sure it's updated to reflect the content / title of the page.

Again it depends on what application you're using SilverStripe for. If it's for yourself, no problem I guess. ;-)