Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » conditional includes

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

Page: 1
Go to End
Author Topic: 1290 Views
  • Daimz
    Avatar
    Community Member
    36 Posts

    conditional includes Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: conditional includes Link to this post

    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 %>

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: conditional includes Link to this post

    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

  • Daimz
    Avatar
    Community Member
    36 Posts

    Re: conditional includes Link to this post

    That worked wonderfully thank you both.

    1290 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.