footer.cfm, and then using
<cfinclude>on every single page to include them. The popular way to do it looks something like this:
<cfinclude>your headers and footers in every view in your Wheels app? Heck no! If the structure of your pages ever changed, you would need to edit every single page on your site to make the fix.
viewsfolder or contained in one of the controllers' view folders. Let's go over how layouts work, starting with the simplest way and then moving on to more complex setups.
views/layout.cfmfile. In a fresh install of Wheels, you'll notice that it only contains a few lines of code:
titlebeing output in between the
<title>tags. This would require that any controller or view using this particular layout would need to set a variable named
<cfparam>tags at the top of your layout files. That way any developer using your layout in the future could easily see which variables need to be set by the controller.
views/layout.cfm. Think of it as the default layout to be used by any given controller.
pressand there is no layout created for
press, Wheels will automatically use
views/layout.cfmas the layout.
presscontroller, then that layout will be used instead of the default layout.
blog. To do this, you would simply create the layout and save it as
controllers/Blog.cfcfile, all actions will now wrap their contents with the
bloglayoutone.cfmfile instead of the
blogLayoutOnelayout for any actions in this controller except for the
homeaction. In the case of the
homeaction, it will fall back to the default behavior (i.e. using the
config()function runs only once per application and controller. This is why you can't perform the logic that decides which layout to use directly inside the
config()function itself. Instead, you tell Wheels to always run the
resolveLayoutfunction on each incoming request.
layoutargument is to look for the file in the current controller's view folder, so here we're still assuming that the
displayaction is in the
.cfmextension will also be added automatically by Wheels, so you don't need to specifically include that part.
layoutargument with a forward slash,
/. By doing this, Wheels will know you want to start the search in the root of the
viewsfolder. Let's say that you're storing all miscellaneous layouts in its own folder, simply called
layouts. You would display one of them with the following code:
layout.cfmyou can actually remove the "layout" string above since the default for includeLayout() is
layoutanyway. We're just including it here for completeness and to show that you can of course achieve this regardless of what your parent layout file is named.