hogan.js with master pages or layouts
Asked Answered
R

2

7

Is it possible in any way to use hogan.js as template engine with layouts something like "Razor or master pages in .NET"? I would get a result like this:

layout.hjs: contains "header" & "footer"

and

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

Renee answered 25/9, 2013 at 12:2 Comment(0)
T
9

sure:

layout.hjs:

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

index.hjs:

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

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

btw. this is [email protected], get it with a git url with mpn

Toddler answered 18/12, 2013 at 19:33 Comment(0)
C
1

I'm not sure what you mean, "Razor or master pages in .NET"? What are you looking to do, use view partials?

But the basic way of setting up 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 if it's inside your package.json already or not.

Then you just make a views directory and throw an index.hjs file and you're set.

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

Crossfertilization answered 17/12, 2013 at 23:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.