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.

Customising the CMS /

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

conditional includes


Go to End


4 Posts   2186 Views

Avatar
Daimz

Community Member, 36 Posts

17 August 2009 at 2:35am

How can I use an include so that it only appears on a certain page.

I am using $layout to call my HomePage information as well as all the others however in a different area of the html altogether I need to include a footer that will only show when viewing the homepage. However I can't put it in the HomePage file as it would mess with my layout.

I have been trying this:

	<% if HomePage %>
<% include Footer %>
<% end_if %>

but it is not working. How can I get this working?
Thanx in advance

Avatar
Willr

Forum Moderator, 5523 Posts

17 August 2009 at 9:19am

This should work as long as you have a function HomePage which returns true / false if its on the homepage or not. For example if you want to use your html you would need a function like

function HomePage {
return ($this->URLSegment == "home") ? true : false;
}

Otherwise you can do this in your template

<% if URLSegment = home %>
....
<% end_if %>

Avatar
dhensby

Community Member, 253 Posts

17 August 2009 at 11:51am

Yes, that is one way of doing it for sure. You would require a function with the name HomePage.

However, i would use the inbuilt function ClassName (as i always have a 'homepage' page type. ClassName will return the name of the class, ie: Page, or HomePage, etc.

So you can either do:

function HomePage() {
return ($this->ClassName() == 'HomePage') ? true : false;
}

OR
<% if ClassName = HomePage %>
...
<% end_if %>

I would do the second one to save on redundant code.

Hope that helps.

PS: more info @ http://doc.silverstripe.com/doku.php?id=built-in-page-controls#titles_and_cms_defined_options

Avatar
Daimz

Community Member, 36 Posts

17 August 2009 at 1:34pm

That worked wonderfully thank you both.