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.

Themes /

Discuss SilverStripe Themes.

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

[SubSubPage]_Controller extending [SubPage]_Controller extending Page_Controller


Go to End


6 Posts   2288 Views

Avatar
Punch Rockgroin

Community Member, 8 Posts

13 February 2010 at 12:09pm

Edited: 13/02/2010 12:09pm

Is this possible? I tried it out and it didn't seem to work for me... maybe I'm missing something or just not possible.

I have a site I'm building where there are two different types of pages - a "Wide" class and a "Narrow" class. What I'd like to do is make sure that the Wide and Narrow classes contain the appropriate layouts. So for example:

main "Shell" Page
<body>....

$Layout (would contain wide page layout)

...</body>

Wide Page:
<section id="MainContent" class="wide" >
<article id="Content">
$Layout (would contain calendar page layout)
</article>
</section>

and the "subpage" of Wide Page would be Calendar page

<div id="CalendarContent">
$Content (actual calendar content)
</div>

and the page controllers going like this

class WidePage_Controller extends Page_Controller {

}

class CalendarPage_Controller extends WidePage_Controller {

}

or am I missing the point? The rest of SS has come excessively easy but I don't know if this would work at all...

Thanks!

Avatar
bummzack

Community Member, 904 Posts

14 February 2010 at 12:06am

Edited: 14/02/2010 12:06am

Hi and welcome to the forums

Your approach looks fine. You can subclass the Page class, and then subclass your classes again.
You can't have nested $Layout statements though. But there are lots of other possibilities to customize your layout. One is to create different classes with different layout files, or you could use one class that switches layout depending on the context, or use flags and <% if Flag %> constructs in your layout.

Can you be a little more specific on what you're trying to achieve and what didn't work? Did you do a dev/build

Avatar
Punch Rockgroin

Community Member, 8 Posts

14 February 2010 at 12:18am

Basically, I want to have a an outer shell, the Page class that has outer layouts like backgrounds and footers and a lower section that is static across all pages.

Then, there are two different types of inner shells, a wide version that's styled with a certain css class and a narrow version that has another css class styling, but also contains a sidebar.

Finally, all of the other pages would either be extended off of the wide or narrow pages depending upon what they are: calendar, food menu, map page would be wide to accommodate whatever they contain; contact, blog, etc would be narrow as the content wouldn't need to stretch across, thus allowing for a side bar with relatively static info or widgets. A third level so to speak.

I was just looking for a way not to have to keep duplicating wide or narrow second level items over and over again in the third level, and maybe have other stuff like CMS fieldtabs propagate down to the third class as well.

Avatar
bummzack

Community Member, 904 Posts

14 February 2010 at 1:04am

Well your "outer shell" is the Page.ss file in the templates folder.
You could create two classes WidePage and NarrowPage which have both different layout files. As an example, the NarrowPage can also contain a WidgetArea in the CMS.
Then just subclass WidePage or NarrowPage. Eg. Blog would extend NarrowPage.

If the blog doesn't require a special template, it will default to the NarrowPage.ss Layout (a lot of how the templates work is described in tutorial 1).
If you need a custom template, just create Blog.ss for the blog and use includes for areas that are used in multiple templates... that way you can avoid writing code multiple times.

Avatar
Punch Rockgroin

Community Member, 8 Posts

14 February 2010 at 1:22am

Hmm... I thought that's what I did, but I couldn't get it to work. I'll go back and revisit the code, but at least I know it is possible.

It would be like:

class WidePage extends Page{

}

then

class CalendarPage extends WidePage{

}

Am I on the right path? I looked through that first tutorial but I didn't see anything about extending further than the one level - but is it similar to the "home page" section?

Avatar
bummzack

Community Member, 904 Posts

14 February 2010 at 4:08am

Yeah, it should work, you can extend as many levels you want.
Make sure you always extend the page class and the controller class.
Like this:

class WidePage extends Page {

}

class WidePage_Controller extends Page_Controller {

}

and

class CalendarPage extends WidePage {

}

class CalendarPage_Controller extends WidePage_Controller {

}

etc.

And don't forget to run dev/build after adding new classes.