Skip to content

View Helpers

includeContent()

includeContent() — returns string

Available in: controller Category: Miscellaneous Functions

Used to output the content for a particular section in a layout.

NameTypeRequiredDefaultDescription
namestringnobodyName of layout section to return content for.
defaultValuestringno—What to display as a default if the section is not defined.
encodeanyno—Opt-in HTML encode of the stored section. Default is omitted (no encode) so layouts that store HTML keep working.
// 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>