“A layout is simply an HTML file that acts as your shell where views can be rendered in and exists in the layouts folder of your application. The layout is a complete html document and you basically describe where views will be rendered. Much easier to build and simpler to maintain”.

Here are some notes about layouts (source: ColdBox wiki):

it can be composed of multiple views and one main view

can have as many as needed in your application

are easy to override or assign to different parts of your application

all layouts reside in the layoutsfolder

can also consume other layouts, and hence

can create nested layouts very easily via the renderLayout() method

In this exercise, we will use the Advanced Script ColdBox application template and:

Modify the Main layout to separate out the content for the navigation, body and footer

Create a navigatioin to access users and roles

Please note that the default event by convention is main.index and the default layout for an application is main.cfm.

However, it is possible to choose a different default layout that can be used to render all your views in. This is done by setting that default layout in your Configuration CFC (i.e. in config/ColdBox.cfc) in the layoutSettingsstructure:

As you can see, the navigation, body content and footer for a page are now separated. The benefit of separating the navigation and footer is that we can reuse these same views in all other layouts. We then use the renderView() method to output the contents of the views (nav and footer) and the body content.

Let’s create a separate view for he navand footerviews. Firstly under the viewsfolder, create the tagssubfolder. Within the tags subfolder, create the following files: