express-template-engine
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

Express Template Engine

Easy HTML-based template engine for Express

You can see tutorial here.

Installation

npm i express-template-engine

Setup with Express

import engine from 'express-template-engine'; // ESM, Typescript
const engine = require('express-template-engine'); // CJS

// Set express template engine
app.engine('html', engine({ caching: false }));
app.set('view engine', 'html');

// Set views directory
app.set('views', path.resolve(__dirname, './views'));

// Use template engine
app.get('/', (req, res) => {
  res.render('template', { ... });
});

Function Tags

<eval> Tag

<eval>val</eval>
<eval>javascript.code({});</eval>

Variable Injection (Same as <eval> Tag)

<span>#{val}</span>

<repeat> Tag

<repeat index="i" from="0" to="5">
  <p>Run #{i} times.</p>
</repeat>
<repeat index="i" times="5">
  <p>Run <eval>i</eval> times.</p>
</repeat>

<if>, <elif>, <else> Tag

<if condition="false">
  <p>Content of IF</p>
</if>
<elif condition="val == 'cond'">
  <p>Content of ELIF</p>
</elif>
<else>
  <p>Content of ELSE</p>
</else>

<import> Tag

<import src="another/template"></import>

Package Sidebar

Install

npm i express-template-engine

Weekly Downloads

50

Version

0.2.3

License

none

Unpacked Size

35.8 kB

Total Files

16

Last publish

Collaborators

  • wnynya