Return to v2.5.0 docs

includePartial()


View Helpers Miscellaneous Functions string controller


Includes the specified partial file in the view. Similar to using cfinclude but with the ability to cache the result and use CFWheels-specific file look-up. By default, CFWheels will look for the file in the current controller's view folder. To include a file relative from the base views folder, you can start the path supplied to partial with a forward slash.

Name Type Required Default Description
partial any Yes 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. If you want to have CFWheels display the partial for a single model object, array of model objects, or a query, pass a variable containing that data into this argument.
group string No If passing a query result set for the partial argument, use this to specify the field to group the query by. A new query will be passed into the partial template for you to iterate over.
cache any No Number of minutes to cache the content for.
layout string No 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.
spacer string No HTML or string to place between partials when called using a query.
dataFunction any No true Name of controller function to load data from.

// If we're in the "sessions" controller, CFWheels will include the file "views/sessions/_login.cfm".  
#includePartial("login")# 

// CFWheels will include the file "views/shared/_button.cfm".  
#includePartial(partial="/shared/button")# 

// If we're in the "posts" controller and the "posts" variable includes a query result set, CFWheels will loop through the record set and include the file "views/posts/_post.cfm" for each record.  
<cfset posts = model("post").findAll()> 
#includePartial(posts)# 

// We can also override the template file loaded for the example above.  
#includePartial(partial="/shared/post", query=posts)# 

// The same works when passing a model instance.  
<cfset post = model("post").findByKey(params.key)> #includePartial(post)# 
#includePartial(partial="/shared/post", object=post)# 

// The same works when passing an array of model objects.  
<cfset posts = model("post").findAll(returnAs="objects")> 
#includePartial(posts)# 
#includePartial(partial="/shared/post", objects=posts)# 
</cfoutput>

Related Functions

Miscellaneous Functions