Nested Layouts

Hi people,

I am a newbie with Coldbox (migrating from fusebox) and I was
wondering if it was possible to use nested layouts. For instance, i
want all the actions of a handler to use a nested layout, that
eventually will be wrapped by the main layout. In this way i dont'
have to replicate all the headers, css links, scripts, etc in both
layouts.

Thanks for the replies!

Hernan

yes you can - sort of... but it's a bit more of a manual process (thus
more controllable)

Your layout.cfm will contain all your wrapper bits as you have
described (css, js, headers etc) and will call renderView() in the
middle somewhere.

Now say you have a handler (circuit) FOO that you want to apply a
specific style to for all its views. The most direct port from Fusebox
I can think of would be to call your view as normal, but instead of
outputting the result you save it to a variable. Then call your nested
layout at the end to wrap the output.

For example:

handlerView.cfm: (called by your handler) - this will output your
view content into a variable

<cfsavecontent variable="viewContent">
    my regular view content goes here
</cfsavecontent>
<cfset renderView("nestedLayout")>

nestedLayout.cfm: - take the view content and wrap it into a sub-
layout which will be taken into the main layout

<cfoutput>

</cfoutpout>

layout.cfm

<cfoutput>
<div id="mainWrapper">
    #renderView()#
</div>
</cfoutput>

the end result of this should be:

<div id="mainWrapper">
    <div id="nestedViewWrapper">
            my regular view content goes here
    </div>
</div>

I've done something similar with my app (which I'm also porting from
fusebox, as it happens), but have taken it a step further and created
a LayoutManager plugin (or more accurately - turned an existing cfc
used in the fusebox version into a plugin) -- this is just a
convenience thing which gives me an API for my views to add their
content (customs scripts, css, etc). It's a persistent object and
makes use of flashram to store view data per request.

This was useful to me as we make use of a lot of XSL/XML
transformation to generate forms etc -- this way my views can generate
XML, stash everything in a central place to be transformed when it's
time to render the output.

My Layout.cfm makes a call to another view which accesses the content
stored in the layoutManager and renders it. None of my directly
accessed views actually generate content - they all stash their bits
and pieces as xml in the layoutManager.

Apart from some tidying up in the transition I really haven't had to
change much of the layout code from the original fusebox
implementation - it dropped straight in.

many ways to skin the cat :slight_smile: - hope that helps!

grr - I cut when I should have copied :frowning: here it is again:

handlerView.cfm: (called by your handler) - this will output your
view content into a variable

<cfsavecontent variable="viewContent">
    my regular view content goes here
</cfsavecontent>
<cfset renderView("nestedLayout")>

nestedLayout.cfm: - take the view content and wrap it into a sub-
layout which will be taken into the main layout

<cfoutput>
    <div id="nestedViewWrapper">
            #viewContent#
    </div>
</cfoutpout>

layout.cfm

<cfoutput>
    <div id="mainWrapper">
       #renderView()#
   </div>
</cfoutput>

the end result of this should be:

<div id="mainWrapper">
    <div id="nestedViewWrapper">
            my regular view content goes here
    </div>
</div>

There are several ways to do this; if it’s a simple thing like having a side bar shared across views then just do this in your view file:

#renderView( view=‘tags/left-column’ )#

This will display the views/tags/left-column.cfm content
http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbLayoutsViewsGuide#RenderingMultipleViews

If you want to nested layouts, then the way I tend to do it is something like this:
http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbLayoutsViewsGuide#ContentVariableViews