Fork me on GitHub

Views

The pretty part!


Views are where the HTML rendering happens. Caboose currently only supports HTML views, but will be getting support for things like XML and text.

Rendering Engines

View rendering is done through the consolidate project and supported rendering engines can be found on consolidate's github page. Views can be written using any of the rendering engines supported by consolidate. Just npm install the rendering engine or add it to your package.json and go! You can even mix and match engines for each view.

File naming

[action].[format].[engine] For instance, index.html.ejs would be the index action, where the client requests an html document, and using the ejs rendering engine.

Directory

Views for a controller are located within a directory with the same name as the controller. For instance, if you have a controller named UsersController which would be in the file app/controllers/users_controller.coffee, then the views would be in the app/views/users directory.

Layouts

Layouts are located within the app/views/layouts directory. The default layout is always application.html.[engine]. If you would like to override the layout for a specific controller, just create a layout named [controller].html.[engine] in the layouts directory. Within a layout, you can use the yield method to place the view body. For instance, here's a dead simple application.html.ejs file:

app/views/layouts/application.html.ejs

<html>
  <head>
  </head>
  <body>
    <%- yield() %>
  </body>
</html>
    

Helpers