Ответ 1
Более "HTML-подобный" механизм шаблонов будет nunjucks (синтаксис которого похож на Jinja2, с которым у вас есть опыт).
Здесь простая настройка. Это предполагает, что Express и Nunjucks установлены, если нет:
npm install express
npm install nunjucks
- app.js
var nunjucks = require('nunjucks');
var express = require('express');
var app = express();
app.listen(3012);
nunjucks.configure('views', {
autoescape: true,
express : app
});
app.get('/', function(req, res) {
res.render('index.html', {
title : 'My First Nunjucks Page',
items : [
{ name : 'item #1' },
{ name : 'item #2' },
{ name : 'item #3' },
{ name : 'item #4' },
]
});
});
- views/index.html
<!doctype html>
<html>
<head>
<title>welcome to {{ title }}</title>
</head>
<body>
<ul>
{% for item in items %}
{% include "item.html" %}
{% endfor %}
</ul>
</body>
</html>
- views/item.html
<li>{{ item.name }}</li>