James
James

Reputation: 680

Sails Js view engine with layout sections support?

Does anyone know of a view engine for sails js that has support for optional/required sections in a layout?

Example my layout has:

<html>
<head>
...
css files
...
</head>
<body>
...
<%- body %>
...
js files
...
</html>

So all my view content would end up going where the <%- body %> tag is. But I need page-specific javascript on the page and that javascript relies on the js files included below where the view is injected. Normally in other MVC frameworks they allow you to define other sections in the layout to remedy this, but I haven't been able to find much information on this for sails js.

Sure, I could just put my js includes on the layout into the head tag, but that's a pretty big cop out to get around not having layout sections.

Upvotes: 2

Views: 225

Answers (2)

James
James

Reputation: 680

Dust has what I am looking for: http://akdubya.github.io/dustjs/

File: base.dust
<html>
    <head>
    ...
    css files
    ...
</head>
<body>
    ...
    {+body/}
    ...
    js files
    {+javascript/}
    ...
</html>


File: homepage.dust
{>base/}
{<body}
    my home page content body
{/body}
{<javascript}
    my page specific javascript.
{/javascript}

Upvotes: 2

Matan Gubkin
Matan Gubkin

Reputation: 3099

You can just inject the js files on the bottom of your contet layout.

Upvotes: 0

Related Questions