View Helpers
includeContent()
Signature
Section titled “Signature”includeContent() — returns string
Available in: controller
Category: Miscellaneous Functions
Description
Section titled “Description”Used to output the content for a particular section in a layout.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | no | body | Name of layout section to return content for. |
defaultValue | string | no | — | What to display as a default if the section is not defined. |
encode | any | no | — | Opt-in HTML encode of the stored section. Default is omitted (no encode) so layouts that store HTML keep working. |
Examples
Section titled “Examples”// 1. Output the main page body inside a layout (default section is "body")
// In `app/views/layout.cfm`:
<html>
<head>
<title>My Site</title>
</head>
<body>
<cfoutput>
#includeContent()#
</cfoutput>
</body>
</html>
// 2. Define a named section in a view, then render it in the layout
// In `app/views/blog/show.cfm`:
contentFor(head='<meta name="description" content="Read our latest post">');
// In `app/views/layout.cfm`:
<html>
<head>
<title>My Site</title>
<cfoutput>#includeContent("head")#</cfoutput>
</head>
<body>
<cfoutput>#includeContent()#</cfoutput>
</body>
</html>
// 3. Provide a default value when a section may not have been defined
<cfoutput>
#includeContent(name="sidebar", defaultValue="<p>No sidebar content.</p>")#
</cfoutput>