Hogan.js layouts

319 Views Asked by At

I trying to get the layout and content in separate files in express.js without using systems rendering engine (barebones hogan)

I have layout.html and index.html but i don't know how to properly make it.

Here are my files:

layout.html
{{> header}}
{{$content}}
  default content
{{/content}}
{{> footer}}


index.html
{{<layout}}
  {{$content}}
    your content goes here
  {{/content}}
{{/layout}}

and my script

  var layout;
  fs.readFile('layout.html','utf-8',function (err,view) {
    layout = view;

  });


  fs.readFile('index.html','utf-8',function (err,view) {

    var content = Hogan.compile(view);
    var t = Hogan.compile(layout);
    var s = t.render({},{'content':content});
    res.send(s);
  });

I get only layout default value and not content values.

1

There are 1 best solutions below

0
Rik On

I found it.

var content = Hogan.compile(index);
var t = Hogan.compile(layout);
var s = content.render({},{'layout':layout});
res.send(s);