Skip to content

View Helpers

contentForLayout()

contentForLayout() — returns string

Available in: controller Category: Miscellaneous Functions

contentForLayout() is used to render the main content of the current view inside a layout. In Wheels, when a controller action renders a view, that view generates content. This content can then be injected into the layout at the appropriate place using contentForLayout(). Essentially, it’s the placeholder for the view’s body content in your layout template.

Controller:
// PostsController.cfc
function show() {
    var post = model("post").findByKey(params.id);
}

View (views/posts/show.cfm):
<h2>#post.title#</h2>
<p>#post.body#</p>

Layout (views/layout.cfm):
<html>
<head>
    <title>Blog</title>
</head>
<body>
    <nav>Home | Posts</nav>

    <!-- Inject view content -->
    #contentForLayout()#

    <footer>© 2025 My Blog</footer>
</body>
</html>

Output when visiting /posts/show?id=1:
<html>
<head>
    <title>Blog</title>
</head>
<body>
    <nav>Home | Posts</nav>

    <h2>Hello World</h2>
    <p>This is my first post!</p>

    <footer>© 2025 My Blog</footer>
</body>
</html>