Hogan.js with main pages or layouts

Is there any way to use hogan.js as a template engine with layouts, for example "Razor or master pages in .NET"? I would get this result:

layout.hjs: contains the header and footer

and

index.hjs: will include layout.hjs and only contain page content.

+7
layout express master
source share
2 answers

what:

layout.hjs:

{{> header}} {{$content}} default content {{/content}} {{> footer}} 

index.hjs:

 {{<layout}} {{$content}} your content goes here {{/content}} {{/layout}} 

see the hogan test file for everything it can do: https://github.com/twitter/hogan.js/blob/master/test/index.js

by the way. this is Hogan@3.0.0 , get it from git url with mpn

+9
source share

I'm not sure what you mean: "Razor or master pages in .NET"? What do you want to do, use partial views?

But the main way to configure Hogan.js for Express is as follows:

 var express = require('express'); var app = express(); app.set('views', __dirname + '/views'); app.set('view engine', 'hjs'); app.use(app.router); app.use(express.static( __dirname + '/public' )); app.get('/', function( req, res, next ) { res.render('index'); }); app.listen(3000); 

You will have to npm install express [--save] , npm install hjs [--save] , depending on whether it is inside your package.json package or not.

Then you simply create the submission directory and drop the index.hjs file and you install it.

Let me know what you want to do with your templates, and we can work from there.

+1
source share

All Articles