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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Layout in Layout


Go to End


4 Posts   740 Views

Avatar
Bereusei

Community Member, 96 Posts

24 October 2013 at 3:35am

Hey Guys,

I have a Page.ss where my main layout sit. Then I have in the layout folder an ContentPage.ss, which is later placed in Page.ss. So far so easy.
Now I wanna go one level deeper: What I need is a SubContentPage.ss as child from the ContentPage.ss. The content from SubContentPage should be placed in ContentPage and ContentPage again in Page.ss.

Page.ss:

<html>
<body>...</body>
...
$Layout
....
</html>

Layout/ContentPage.ss
<div class="Layout_from_ContentPage">
<div class="Content">$Layout_Layout</div>
</div>

And now I need something like this:
Layout/Layout/SubContentPage.ss

<div class="subcontent">$MyText</div>

At the end I want this structure:

  • StartPage

  • AboutMePage

  • ContentPage
    • SubContentPage1

    • SubContentPage2

    • SubContentPage3

I hope my description is clear. Is this possible?

Attached Files
Avatar
Bambii7

Community Member, 254 Posts

24 October 2013 at 2:58pm

Inside your Page class you could add a function titled SubContent (or SubLayout). And return a rendered HTML block eg

		public function SubContent() {
			return $this->renderWith( 'Sub' . $this->class, array( 'Subcontent' => $this->SubSomeVarOrRelation ) );
		}

Then inside your includes folder have SubPage.ss & SubContactPage.ss etc.
And either in your main Page.ss or individual layout pages include the var $SubContent

The rendering will depend on how you're handling the SubContent. Are you just going to have an HTML field in the page, or are these going to be a list of DataObjects, or potentially one of many DataObjects.

Avatar
Bereusei

Community Member, 96 Posts

25 October 2013 at 2:42am

Thank you for response. rendeWith works fine. But the pagetype from my SubContentPage needs to be ContentPage, doesn´t it?
In my case all Children of ContentPage must have another pagetype.

Avatar
Bambii7

Community Member, 254 Posts

25 October 2013 at 11:36am

Might need some more info on how you're making the SubeContent? Can you paste some code?

If they're nested child pages you could make an include file in themes/templates/Includes/RenderChildren.ss

And there loop over the children
<% loop Children %>
Render Sub Child Page stuff
<% end_loop %>

and then include it in your main page
<% if Children %>
$RenderChildren
<% end_if %>