5093 Posts in 1516 Topics by 1113 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1117 Views |
-
conditional includes

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 -
Re: conditional includes

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 %> -
Re: conditional includes

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
| 1117 Views | ||
|
Page:
1
|
Go to Top |



