Skip to content

Controller

renderPartial()

renderPartial() — returns any

Available in: controller Category: Rendering Functions

Instructs the controller to render a partial when it’s finished processing the action.

NameTypeRequiredDefaultDescription
partialstringyes—The name of the partial file to be used. Prefix with a leading slash (/) if you need to build a path from the root views folder. Do not include the partial filename’s underscore and file extension.
cacheanyno—Number of minutes to cache the content for.
layoutstringno—The layout to wrap the content in. Prefix with a leading slash (/) if you need to build a path from the root views folder. Pass false to not load a layout at all.
returnAsstringno—Set to string to return the result instead of automatically sending it to the client.
dataFunctionanynotrueName of a controller function to load data from.
statusstringno[runtime expression]Force request to return with specific HTTP status code.
// 1. Render the partial `_comment.cfm` located in the current controller's view folder
renderPartial("comment");

// 2. Render the partial at `app/views/shared/_comment.cfm` using an absolute path
renderPartial("/shared/comment");

// 3. Return the rendered partial as a string instead of sending it to the client
commentHtml = renderPartial(partial="comment", returnAs="string");

// 4. Render a shared partial wrapped in a layout and cache it for 5 minutes
renderPartial(partial="/shared/sidebar", layout="/layouts/sidebar", cache=5);

// 5. Render a partial using a named data-loading function to supply variables
//    (the controller must have a private function named `comment` returning a struct)
renderPartial(partial="comment", dataFunction="comment");

// 6. Render a partial and force a specific HTTP status code (e.g. for AJAX responses)
renderPartial(partial="/shared/error", status=422);