A lightweight markdown engine for Express.
$ npm i
$ npm t
'use strict';
var express = require('express');
var markdownEngine = require('./util/markdown-engine');
var app = express();
app.engine('md', markdownEngine.configure());
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'md');
...
<!DOCTYPE html>
<html>
<head>
<title>{{title}}</title>
</head>
<body>
{{body}}
</body>
</html>
Templates are written using Markdown and provide basic templating features.
My middle name is {{name}}
res.render('template', { name: 'danger' });
My middle name is danger
Partials can be included by using the following syntax:
{{> partial}}
{{> path/to/partial}}
By default, partials are expected to be located in the views/partials/
directory.
Template caching is enabled only in production. NODE_ENV=production
The configure call accepts an Object
as an argument. It is not required, but allows you to specify a basePath
for the engine. By default partials and templates are expected to live in the views
directory in the root of your project. If your this directory happens to be placed somewhere else, use basePath
to define it.
app.engine('md', markdownEngine.configure({basePath: __dirname});