Jump to:

1347 Posts in 439 Topics by 514 members

Themes

SilverStripe Forums » Themes » Holder for childpages to create layout

Discuss SilverStripe Themes.

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

Page: 1 2
Go to End
Author Topic: 10959 Views
  • shrike
    Avatar
    Community Member
    15 Posts

    Re: Holder for childpages to create layout Link to this post

    Hmm, but isn't this model then printing only one layout based on PageType and then I have to create the final layout again? I have idea to use already made layout. In this case product 1 page and product 2 page -this way I do not have to make layout again in page holder as the holder only should render the already made layout from the product page 1 and 2 (which are a child pages inside sitetree in CMS). If I have 10 child pages, the holder will be as tall as skyscraper. If I change the order in sitetree and then it automatically changes order in holder also.

    Is holder/controller even the right word for whole idea? Dynamically include all child pages with layout after each other in one parent page? Humor: <% if hasChildren %> <% include all children pages with content and $Layout here inside parent in CMSSiteTree order %> <% end>

    Has RenderWith() any use in here?

    Thanx!

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: Holder for childpages to create layout Link to this post

    A very common approach in SilverStripe templating is the use of includes:

    <% control Children %>
       <% if ClassName = PageType1 %>
          <% include Layout1 %>
       <% elseif ClassName = PageType2 %>
          <% include Layout2 %>
       <% end_if %>
    <% end_control %>

    You'd have Layout1.ss and Layout2.ss in your Templates/Includes/ directory. Then you could use the same includes to load the appropriate layout within your Pagetype1.ss and your Pagetype2.ss templates for the actual pages...

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: Holder for childpages to create layout Link to this post

    Getting back to this - it still is more complex then I thought... The examples would work - but only if in the original layout for the different pagetypes no Controller functions are used, because these are not available from within a control loop. You would need access to the different page controllers and have them render the templates.

    So I've set up an idea that might work. It's very basic, and I've no idea how it would affect resources, but...

    In the Page class:

    function RenderAsChild() {
       $class = $this->ClassName . "_Controller";
       $controller = new $class($this);
       return $controller->renderForHolderPage();
    }

    In the Page_Controller class

    public static $LayoutTemplate = 'CustomPageLayout';

    function renderForHolderPage() {
       $template = $this->stat('LayoutTemplate');
       if ($template) return $this->renderWith(array($template));
       else return '';
    }

    Now you need only set a different LayoutTemplate for each PageType (could even do it from _config) to determine what template to use - with full access to all controller methods. The HolderPage template just needs this:

    <% control Children %>
       $RenderAsChild
    <% end_control %>

    [EDIT] forgot to return the template from the RenderAsChild method. Added that. Also need to use $this->stat to access appr. template...

  • shrike
    Avatar
    Community Member
    15 Posts

    Re: Holder for childpages to create layout Link to this post

    Now we are getting there! Great idea, got to check this out.

  • shrike
    Avatar
    Community Member
    15 Posts

    Re: Holder for childpages to create layout Link to this post

    This works perfectly! Thanx for help. Only Pages with WidgetArea are not working, but it is not a problem in this case.

  • shrike
    Avatar
    Community Member
    15 Posts

    Re: Holder for childpages to create layout Link to this post

    Ok, new ideas needed again to solve problem with <% include SomePart %>. If for example page type "1Col" is used without this renderforHolderpage-method, includes works fine. But when the "1Col" is used as a child page under this holder-page, includes are not working anymore.

    Is it possible to make some kind of add on to this code to make it work, or is it just a limitation of the system?

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