Package Exports
- express-posthtml
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (express-posthtml) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
PostHTML
View Engine for Express
Install
(sudo) npm i -S express-posthtml
Usage
Engine
Register PostHTML as View Engine
app.engine('html', require('express-posthtml'))
app.set('views', /* Path to views */)
app.set('view engine', 'html')
Plugins
Global
All Views will be render with this plugin setup, if no local setup provided.
app.set('view options', [ PostHTML Plugins ])
res.render('file')
Local
View specific setup by adding plugins separately to the respective routes. Note that if you have set plugins globally, routes with local setup will not use the global setup by default.
app.set('view options', [])
res.render('file', { plugins: [ PostHTML Plugins ] })
Extend
If views share common plugins (e.g BEM), but view specific additions are necessary, use the extend option. Now the global setup is used and will be extended with the local plugins of the respective route.
app.set('view options', [ PostHTML Global Plugins ])
res.render('file', { plugins: [ PostHTML Local Plugins ], extend: true, })
Example
var express = require('express')
var app = express()
// Engine
app.engine('html', require('express-posthtml'))
// Settings
app.set('views', /* Path to views */)
app.set('view engine', 'html')
app.set('view options', [/* PostHTML Plugins */]) // Global Setup
// Global Use
app.get('/', (req, res) => {
res.render('file')
})
// Local
app.get('/local', (req, res) => {
res.render('file', { plugins: [/* PostHTML Plugins */] } )
})
// Extend
app.get('/extend', (req, res) => {
res.render('file', { plugins: [/* PostHTML Plugins */], extend: true } )
})
app.listen(3000, () => {
console.log('Server started!')
})