express-twig-layout
express-twig-layout is a layout system based on twig.
Instalation
$ npm install express-twig-layout
Exemple:
This exemple use express and express-twig-layout
install express and express-twig-layout
$ npm install --save express $ npm install --save express-twig-layout
index.js
Create a simple express app with two route: /home and /test
const express = const layout = const app = //set the views directoryapp app //home routeapp //test routeapp app app
/views/page/default.html
The template for the page.
For the template syntax read the twig js documentation
<!-- block head --> {{ getBlockHtml('head') }} Home Test <!-- block content --> {{ getBlockHtml('content') }} footer
/views/page/head.html
template for the head block define in the file views/page/default.html
{{ title }} {% for css in this.css %} {% endfor %} {% for js in this.js %} {% endfor %}
/views/home.html
The template for the /home route
{{ this.title }}
/views/test.html
The template for the /test route
{{ this.title }}
Run:
$ node index.js