@totemish/nunjucks-middleware
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Totemish Nunjucks Middleware

This package adds support for Nunjucks in @totemish/framework.

Installation

npm i --save @totemish/framework nunjucks @totemish/nunjucks-middleware

Description

NunjucksMiddleware uses the @totemish templateDirs to get the path to the template file, concatenating it with the controller-specific templateUrl. To learn more about @totemish routing, check here. NunjucksMiddleware accepts all the default Nunjucks options as an argument. E.g. you can provide watch, cache, etc. For more information about Nunjucks options, check here.

Usage

You can enable this middleware globally (preferably as global end middleware as controller result object is unavailable when global start middleware is executed) like so:

import { Server } from '@totemish/framework';
import { NunjucksMiddleware } from '@totemish/nunjucks-middleware';

Server.globalMiddleware.add('end', NunjucksMiddleware());

Alternatively, you can enable it for specific routes by passing it to the array of controller middleware:

import { Controller } from '@totemish/framework';
import { NunjucksMiddleware } from '@totemish/nunjucks-middleware';

@Controller({
  route: '/',
  templateUrl: 'index.njk',
  middleware: [
    NunjucksMiddleware(),
  ]
})
export class IndexController {}

TODO

  • More tests
  • Support for providing custom template files
  • Rendering template strings

/@totemish/nunjucks-middleware/

    Package Sidebar

    Install

    npm i @totemish/nunjucks-middleware

    Weekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators