Socket
Socket
Sign inDemoInstall

multiplex-templates

Package Overview
Dependencies
Maintainers
9
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiplex-templates

Easy embedding for multiple template languages


Version published
Weekly downloads
65
increased by32.65%
Maintainers
9
Weekly downloads
 
Created
Source

multiplex-templates

Embed components in other components!

Build Status Code Climate

Install

npm install --save multiplex-templates

Usage

render a template

var multiplex = require('multiplex-templates')();

multiplex.render('path/to/template.ext', data);

This will render a template. The templating engine it uses is determined by the template's extension.

e.g.

components/paragraph/template.jade
templates/header.nunjucks

Engines

We support all of the engines that consolidate.js supports.

This module exposes the instances of the templating engines, so you can add mixins/filters/globals/etc onto them:

var env = multiplex.engines.nunjucks;

env.addGlobal('key', 'value');

You can also instantiate your own engines (and configure them however you like) and pass them into multiplex-templates.

var env = require('nunjucks').configure('.', { watch: false }),
  jadeEnv = require('jade'), // so cool, doesn't need config (⌐■_■)
  multiplex = require('multiplex-templates')({
    nunjucks: env,
    jade: jadeEnv
  });

// multiplex.engines.nunjucks === env

Cross-engine Embedding

To embed a template, call the embed function in the parent template, passing in the name of the template you want to embed, plus (optionally) data and defaults objects. The embed function is available in all templating languages that allow functions inside template locals.

Nunjucks:

{{ embed('path/to/tpl.nunjucks', data) | safe }}

Jade:

section#foo
  p.embedded
    != embed('path/to/tpl.jade', data)

The data you pass in is then used to render the child template. You can optionally pass in additional data:

Nunjucks:

{{ embed('path/to/tpl.mustache', data, defaults) | safe }}

Jade:

section#foo
  p.embedded
    != embed('path/to/tpl.ejs', data, defaults)

Properties in the data object will overwrite properties of the same name in the defaults object, as this uses lodash's fast _.defaults() method.

Tests

npm test

FAQs

Package last updated on 05 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc