You are viewing documentation for v1.1.x. Change

usesLayout()

Description

Used within a controller's init() method to specify controller- or action-specific layouts.

Function Syntax

usesLayout(template [, ajax, except, only, useDefault ])

Parameters

Parameter Type Required Default Description
template string Yes Name of the layout template or method name you want to use
ajax string No Name of the layout template you want to use for AJAX requests
except string No List of actions that SHOULD NOT get the layout
only string No List of action that SHOULD ONLY get the layout
useDefault boolean No true When specifying conditions or a method, pass true to use the default layout.cfm if none of the conditions are met

Examples

<!---
    Example 1: We want this layout to be used as the default throughout the entire
    controller, except for the myajax action
--->

<cffunction name="init">
    <cfset usesLayout(template="myLayout", except="myajax")>
</cffunction>

<!---
    Example 2: Use a custom layout for these actions but use the default layout.cfm
    for the rest
--->

<cffunction name="init">
    <cfset usesLayout(template="myLayout", only="termsOfService,shippingPolicy")>
</cffunction>

<!--- Example 3: Define a custom method to decide which layout to display --->
<cffunction name="init">
    <cfset usesLayout("setLayout")>
</cffunction>

<cffunction name="setLayout">
    <!--- Use holiday theme for the month of December --->
    <cfif Month(Now()) eq 12>
        <cfreturn "holiday">
    <!--- Otherwise, use default layout by returning `true` --->
    <cfelse>
        <cfreturn true>
    </cfif>
</cffunction>