Jump to:

1347 Posts in 439 Topics by 514 members

Themes

SilverStripe Forums » Themes » [SubSubPage]_Controller extending [SubPage]_Controller extending Page_Controller

Discuss SilverStripe Themes.

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

Page: 1
Go to End
Author Topic: 1359 Views
  • Punch Rockgroin
    Avatar
    Community Member
    8 Posts

    [SubSubPage]_Controller extending [SubPage]_Controller extending Page_Controller Link to this post

    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!

  • banal
    Avatar
    Community Member
    901 Posts

    Re: [SubSubPage]_Controller extending [SubPage]_Controller extending Page_Controller Link to this post

    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

  • Punch Rockgroin
    Avatar
    Community Member
    8 Posts

    Re: [SubSubPage]_Controller extending [SubPage]_Controller extending Page_Controller Link to this post

    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.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: [SubSubPage]_Controller extending [SubPage]_Controller extending Page_Controller Link to this post

    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.

  • Punch Rockgroin
    Avatar
    Community Member
    8 Posts

    Re: [SubSubPage]_Controller extending [SubPage]_Controller extending Page_Controller Link to this post

    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?

  • banal
    Avatar
    Community Member
    901 Posts

    Re: [SubSubPage]_Controller extending [SubPage]_Controller extending Page_Controller Link to this post

    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.

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