CompoundJS and Jade templates

125 Views Asked by At

I'm using "Jade" view engine with CompoundJS, however it doesn't use the proper Jade workflow when I call the render() method within a controller (e.g. its always rendering the same layout, yielding the inner template as the body parameter of the layout).

I need to know how to either:

  • Change the layout from the controller (its always using application_layout.jade) and be able to render without layout
  • Render views normally, so that I have the layout specified within the view template itself (e.g. by specifying explicitly which template I'm extending, with a Jade directive like "extend layout")
2

There are 2 best solutions below

0
On

You can specify a different layout to be used before you call render in a controller action with

this.layout = "myLayout"; // uses app/assets/views/layouts/myLayout_layout.[ejs/jade/etc.]
this.layout = false; // uses no layout
render();

I don't think it's possible to specify a layout in the view template

0
On

You can override the application_layout with your own. It is convention-based.

For example, if you want to override the login view with a different layout, you would add a new template app/views/layouts/login_layout.ejs.

The inner template is specified as <%- body %>.

<!-- Different markup before -->
<%- body -->
<!-- Different markup after -->