部分与Hogan.js

我想首先说我是Node.js的新手。


我的问题是这个。 有没有一种方法可以使用单个布局的HTML? 类似于MCV和ASP中的共享视图主布局

例如:

//。 hello_world.hjs

<!DOCTYPE html> <html> <head> <title>{{ title }}</title> <link rel='stylesheet' href='/stylesheets/style.css' /> </head> <body> <h1>{{ title }}</h1> <div id="content"> <!-- Place changing page content here --> {{> part }} </div> <footer> {{date}} </footer> </body> </html> 

//。 hello_world.js

 var express = require('express'); var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { res.render('hello_world', { title: 'Hello World!', partials: { part: 'part' } }); }); 

//。 part.html

 <h1>This is a part</h1> 

我只希望改变在div中的内容与id“内容”在hello_world.hjs这样,当更新是对页脚或导航栏更改将不必对每个文档。


文件夹结构 – >

 routes -- hello_world.js views --hello_world.hjs --part.html --index.hjs 

我试图寻找一个解决scheme。 但是,我不确定在search中是否使用了正确的术语。

part.html必须重命名为part.hjs。 但是,这仍然不能回答整个问题。 虽然我现在能够使用partials我需要能够使用一致的布局,我不想在JS文件中重复自己,例如:

 partials: { part: 'part', footer: 'footer' } 

重新浏览一个大型网站会变老,容易出现拼写错误。