Nesting of layouts

Because layouts are just pages, it is legal and by design to have a layout page refer to another layout page, creating nested layouts. In this sample, the nested-layout-department.layout in fact references the nested-layout-company.layout, which is what we call our master layout or outermost layout, while the nested-layout-usage.cxp page is being referred to as the innermost page. Be reminded: all pages in the rendering process of the final content share the same HttpRequest object, but also the session and data collections. In this example, we use the ::session collection to transport some data from the content page through all layout pages.
A nested layout is any layout that refers to another (outer) layout. This approach is useful when a subset of pages requires the same markup, as is often the case when certain sections of a website or web application need to appear slightly different from the others while retaining the same look and feel. In this layout file, we write out the department description and the content of the content page. We also create a footer section to be rendered in the referenced layout nested-layout-company.layout. Note: it is important to explicitly render the body within each layout page, eg. using :renderSection("body")! If this is not done, the content gets lost.
The layout nested-layout-company.layout is the master layout for the company (root page).

Related articles:
Run in new tab
Live editor
Result built with V2 2156
I'm a warning toast!
I'm a success toast!