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.

General Questions /

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

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

Different pages per menu Item


Go to End


9 Posts   2764 Views

Avatar
borriej

Community Member, 267 Posts

29 January 2010 at 11:39pm

Edited: 11/08/2010 9:09am

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!

Avatar
Zauberfisch

Community Member, 30 Posts

30 January 2010 at 12:31am

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

Avatar
borriej

Community Member, 267 Posts

30 January 2010 at 12:47am

Edited: 30/01/2010 12:47am

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 ? :)

Avatar
Zauberfisch

Community Member, 30 Posts

30 January 2010 at 4:19am

Edited: 30/01/2010 12:51pm

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 ;)

Avatar
borriej

Community Member, 267 Posts

31 January 2010 at 4:48am

Edited: 11/08/2010 9:09am

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

Avatar
Zauberfisch

Community Member, 30 Posts

31 January 2010 at 7:01am

Edited: 31/01/2010 8:41am

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 :D

  • 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 (:

Avatar
borriej

Community Member, 267 Posts

1 February 2010 at 8:42am

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?

Avatar
Zauberfisch

Community Member, 30 Posts

1 February 2010 at 10:32am

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

Go to Top