Setting Views
Views (Default Layout)
The event
object is the object that will let you set the views that you want to render, so please explore its API in the CFC Docs. To quickly set a view to render, do the following:
The view name is the name of the template in the views directory without appending the .cfm. If the view is inside another directory, you would do this:
The views you set will use the default layout defined in your configuration file which by default is the layouts/Main.cfm
We recommend that you set your views following the naming convention of your event. If your event is users.index, your view should be users/index. This will go a long way with maintainability and consistency and also will activate implicit views where you don't even have to use the set view method call.
View With Custom Layouts
You can also use the setView(), setLayout()
methods to tell the framework which view and layout combination to use:
Views With No Layout
You can also tell the framework to set a view for rendering by itself with no layout using the noLayout
argument
setView() Arguments
Here are the arguments for the setView()
method:
Cached Views
You can leverage the caching arguments in the setView()
method in order to render and cache the output of the views once the framework renders it. These cached views will be stored in the template cache region, which you can retrieve or purge by talking to it: getCache( 'template' )
.
View Arguments
Data can be passed from your handler to the view via rc or prc. If you want to pass data to a view without polluting rc and prc, you can pass it directly via the args parameter, much like a method call.
Access the data in the view like so:
No Rendering
If you don't want to, you don't have to. The framework gives you a method in the event object that you can use if this specific request should just terminate gracefully and not render anything at all. All you need to do is use the event object to call on the noRender()
method and it will present to the user a lovely white page of death.
Last updated