Core Framework: Layout Pages

Layout pages are responsible for defining the overall structure of a page. They usually contain the basic HTML structure and tags, style sheet declarations, navigation placement and other elements that are consistent across pages. Additionally, the layout page is responsible for rendering the requested view.

The Layout page is identified by the Layout variable. This variable may be set in either of the following ways:

  • By setting the property this.defaultLayout on Application.cfc.
  • By explicitly passing the layout parameter to the page request.
  • By calling the setLayout() function within an event handler.

The content of the layout variable is a string with the name of a cfm file within the layouts directory without the .cfm extension.

As mentioned before, the layout page is also responsible for rendering the selected view. To render view just do a < cfinclude > to the its associated cfm template. The complete path to the template can be obtained from the viewTemplatePath variable in the request.requestState structure.

The following sample code shows how can a Layout page be constructed to render the selected view.

< html >
    < head / >
    < body >
        < cfinclude template=”../includes/message.cfm” >
        < cfif request.requestState.viewTemplatePath neq "" >
   
< / cfif >
    < / body >
< / html >

Layout pages also typically handle System Messages. This is done by doing a < cfinclude > to the message.cfm file in the includes directory.
 

Overview  |  Controller  |  Event Handlers  |  Views  |  Layouts  |  Services  |  Settings  |  Modules

BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner