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.

Template Questions /

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

The use of $Layout and subtemplates


Go to End


2 Posts   2162 Views

Avatar
fishe

Community Member, 42 Posts

11 January 2009 at 11:33am

Question is whether or not it is possible to use $Layout multiple times in a Page.ss for example. I want to insert "page type specific code" in multiple locations of the Page.ss file - not just the conventional use of $Layout to determine the content area template code by page type but also, for example, parts of the <head> area.

I realise that using $Layout to do this isn't probably the best why but I don't know another way in SS.

Perhaps there is a way to use <% include %> statements conditionally based on Page Type? E.g. <if pagetype == blahblah> or something?

I actually also tried to create a new "Layout-like thing" by creating a directory called "Head", putting a page type specific .ss file in there, and referencing $Head in my root Page.ss file. This didn't seem to work. I guess Layout/$Layout is a hardcoded built in function?

Thanks for any ideas in advance...

Avatar
Carbon Crayon

Community Member, 598 Posts

11 January 2009 at 11:46pm

Hi fishe

how different do your pages need to be? What exactly do you need to be in your header that you can't do with normal functions (like require, $Metadata etc?

You can do conditional statements based on page class like this: <% if ClassName = ClassType %>

That way you could have conditional statements in your include, but that could get a little messy.

If you elaborate on what exactly you need we may be able to find a better way :)