Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multiplex-templates

Package Overview
Dependencies
Maintainers
1
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

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
526
increased by82.01%
Maintainers
1
Weekly downloads
 
Created
Source

multiplex-templates

Embed components in other components!

Build Status Code Climate

Install

npm install --save multiplex-templates

Usage

render a component

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

multiplex.render('component-name', data);

This will render a component. It will look in components/[name]/template.[extension].

e.g.

components/entry/template.jade
components/coolparagraph/template.nunjucks

You can also pass 'component' explicitly as the third arg.

render a layout

multiplex.render('component-name', data, 'layout');

This will look in your root-level layouts folder, e.g.

layouts/index/template.nunjucks
layouts/archive/template.jade

Engines

Currently we support these engines:

  • nunjucks
  • jade
  • mustache (coming soon!)
  • es6 template literals (coming soon!)

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

var env = multiplex.engines.nunjucks;

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

Cross-engine Embedding

Nunjucks

To embed a template, use an embed filter in the parent template. If you configured your nunjucks environment with autoescape: true (highly recommended!), remember to pass the resulting html through |safe so it's not escaped.

{{ data | embed('name') | safe }}

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

{{ data | embed('name', defaults) | safe }}

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 25 Mar 2015

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