Using layout view in Express with Consolidate and Mustache
Posted
by
Raphael Caixeta
on Stack Overflow
See other posts from Stack Overflow
or by Raphael Caixeta
Published on 2012-08-31T05:52:11Z
Indexed on
2012/10/28
17:01 UTC
Read the original article
Hit count: 321
I just started going through Node using Express and finally got Consolidate JS working properly to use Mustache as the templating view system per the instructions on the Consolidate JS Github page.
Mustache is loading properly, but I'm now wondering how to include the layout file along in the rendering of the template. The default Jade system loads the content of the .render method inside of the layout.jade file. I'm just wondering how to do the same, but with Mustache. Any help is greatly appreciated!
Code:
index.js
exports.index = function(req, res){
res.render('index', { title: "Work pl0x?" });
});
index.mustache
Welcome to {{title}}
I just want the index.mustache content to come in the "{{content}}" portion of the code below (layout.mustache). How can I do this?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>Project Name | {{title}}</title>
<link href="/stylesheets/style.css" rel="stylesheet" />
</head>
<body>
{{content}}
</body>
</html>
© Stack Overflow or respective owner