Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Different pages per menu Item

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 1816 Views
  • borriej
    Avatar
    Community Member
    267 Posts

    Different pages per menu Item Link to this post

    Is it possible to have a different template lay-out depending on the menuButton you've clicked?

    See:
    http://www.url.nl/mf/

    When you click 'Verf' I want to use a different lay-out (no image header etc.) than the page.ss

    How to do this?

    Hope you can help me!

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: Different pages per menu Item Link to this post

    yes its possible, you can make a new page type (extending page) and in your template folder you create an new .ss file for your new page type and thats it.

    i'm at work so i don't have enough time to help you any more, but in 4-5 hours i'm at home, then i can help you if you still need help (i'm allways in the IRC channel of silverstripe)

    greetings zauberfisch

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: Different pages per menu Item Link to this post

    Ok, I've searched some information about this item and read http://doc.silverstripe.org/doku.php?id=tutorial:2-extending-a-basic-site

    But I don't understand how SS will know which menu item belongs to which template, how do I do this?

    For instance when you click 'Verf' 'template_verf.ss' must be loaded.

    How do I do this ?

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: Different pages per menu Item Link to this post

    i'm going home now, in 1 1/2 hour i'm at home ...

    notice that i'm also new in silverstripe. but i try my best (:

    //edit:

    so, now i have time ...

    go to mysite/code and create a new file and call it however you want, for exaplme "PageWithoutHeader.php"
    now you open it with a text editor and write into it: http://paste2.org/p/639454

    now we have a new page type whitch has the same properties as the normal page because of the "extends Page" and "extends Page_Controller" in the code

    now you only have 1 thing left to do: creat a template for this page type:

    silverstripe looks in your template folder (themes/{your themes name}/templates) if there is a .ss file witch has the same name (in this case it is "PageWithoutHeader.ss") as the page type it will use this, if its not set it will use the normal Page.ss ( i think thats because we use "extends Page" in our php file^^)

    in your Page.ss there schould be a line "$Layout" this includs a file from the "Layout" folder, now it goes the same way: silverstripe looks in the "Layout" folder, if there is a PageWithoutHeader.ss it will include this one, otherwise it will include the Page.ss

    so if you only want to have a litlle cange in the Page.ss witch is in the Layout folder so you create there a "PageWithoutHeader.ss" and silverstripe will load Page.ss and where $Layout is it will include the "PageWithoutHeader.ss" form Layout folder

    if you need to change something in te Page.ss witch is NOT in the layout folder you only create a "PageWithoutHeader.ss" in the template folder, NOT in the Layout folder, and write your new template

    i hope this is what you are searching for (my english is not the best)
    if you have any qestions .... i'm always in irc if my name is "Zauberfisch|off" you can send me a private message and i will get it when i go online, and maybee i check this fourm for answers tomorrow ;)

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: Different pages per menu Item Link to this post

    Sorry for so late reply, but I was trying to figger it out!

    I've done al your steps:

    - Added PageWithoutHeader.ss in Blackcandy/templates (I've overridden blackcandy template ) This must be the new template without an header for the page: 'Verf', Home must still use Page.ss.
    - Added PageWithoutHeader.php in Mysite/code

    But the site is still the same:
    http://www.url.nl/mf

    I also dont understand how SS will/must know how - for example 'verf' or 'producten' page - need to use the pagewithoutheader.ss?

    Isn't there an option/code that I can say:

    Home: template to use: page.ss
    Verf: use Verf_template.ss
    Producten: use producten_template.ss
    Contact: use contact_template.ss

    Each page looks totally different so I dont want to use an imported code in the page.ss

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: Different pages per menu Item Link to this post

    I also dont understand how SS will/must know how - for example 'verf' or 'producten' page - need to use the pagewithoutheader.ss?

    Isn't there an option/code that I can say:

    Home: template to use: page.ss
    Verf: use Verf_template.ss
    Producten: use producten_template.ss
    Contact: use contact_template.ss

    oh sry, i forgot to tell you how to use the new template

    • to change it for an exsisting page you select your page and go to the tab "Behaviour", there you change the Page type from "Page" to "Page Without Header"
    • if you create a new page witch sould use the other template you click create ant then select in the dropdown menu "Page Without Header" and then click go.

    silverstripe uses the template that has the same name as the page type, so for the page type "PageWithoutHeader.php" it will use the template "PageWithoutHeader.ss" (if it dos not exist it will use the "Page.ss" because we use "class PageWithoutHeader extends Page" in "PageWithoutHeader.php"

    note: silverstripe prints the page type names with a space befor every uppercase letter, for example "PageWithoutHeader.php" will be shown as "Page Without Header" in your admin pannel!

    /edit: if you come into the silverstripe IRC channel i can give you some tipps specific for your special needs (:

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: Different pages per menu Item Link to this post

    Thx for your help and replies, I really appreciate it,

    In the cms under page behavior I can't select the new template. I think this is because we 'extended' the page in the php?

    What should the new php code be of the file PageWithoutHeader.php in 'mysite/code' to get a new template selectable as page type in the CMS?

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: Different pages per menu Item Link to this post

    oh damn it ... sry ... i'm so forgetfully .... :/

    i forgott to tell you that you have to run a dev/build .... in our case it will bee http://www.robvaneckdesign.nl/mf/dev/build

    i hope it work now ....

    1816 Views
Page: 1 2
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.