Automatically include your views with ColdBox

While prototyping a site today, I was looking for a better way for a better way of cutting down some of the programming side so I could focus more on the view templates. ColdBox makes this rather easy with it’s “1 view, 1 layout” concept and hooks into the events. Normally with ColdBox in your handler you’ll need to tell the framework which 1 view you want to use, and then it’ll use your default layout. Why not default the views as well? ColdBox makes doing that simple enough:

[CFM]






[/CFM]

With this function setup as our RequestStartHandler in the config.xml.cfm file we’ll always start the page off with a default view. In this case it’ll look for the view with the path “/views/#handler#/#method#.cfm”. Then if in that controller we need to overwrite the view it’s easy enough; but for the most part you’ll probably be using one view per event. The downside is that if you call another event from inside your handler it’ll still be setup to use whatever event was passed in (at least I imagine this is so).

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments
That is a really cool technique Adam!! Cool!! As for your concern, the answer is no. Because the request start handler will be fired before all your other events. As another technique which might also help you, is setting this up on the pre/post handler methods. That way, you can set up default views for each handler.

So you can have each handler have its own default view that can be setup after it executes via the postHandler method.

Luis

Uh, why do I only see:
[CFM]

[/CFM]

jpyncb plwiumhvt vrxtwknju ogxlf eovlxwnji cwgpxahe dgziqes
Leave a comment

(required)

(required)