2016-05-30 9 views
0

ich versuche, das Layout und den Inhalt in separaten Dateien in Express.js zu erhalten, ohne Systeme Rendering-Engine (Barebone hogan)Hogan.js Layouts

Ich habe layout.html und index.html zu verwenden, aber ich weiß nicht, wie man es richtig macht.

Hier sind meine Dateien:

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


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

und mein Skript

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); 
    }); 

ich nur das Layout Standardwert bekommen und nicht Gehaltswerte.

Antwort

0

Ich habe es gefunden.

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