@springernature/util-dynamic-partial

0.1.0 • Public • Published

Dynamic Partials

NPM version MIT License

Dynamically render a partial within a handlbars template

Allows us to conditionally reference component handlebars templates by registering a handlebars partial file, and providing a helper for dynamically including that template file.

Install

$ npm install @springernature/util-dynamic-partial

Usage

context.json

{
  "dynamicPartials": {
    "partialName": "./path/to/partialName.hbs"
  }
}

Javascript

const Handlebars = require('handlebars');
const dynamicPartials = require('@springernature/util-dynamic-partial');
const config = require('./context.json');

// Register all dynamic partials
(async () => {
  try {
    await dynamicPartials(Handlebars, config.dynamicPartials);
  } catch (error) {
    console.error(error);
  }
})();

HTML (handlebars)

<h2>Include the dynamic partial below</h2>
{{> partialName }}

Find a more complete example in the demo folder.

API

registerDynamicPartials(Handlebars, dynamicPartials, startingLocation)

Return: Promise
Register any number of handlebars partial files as defined within a JSON object

options

Handlebars

Type: Object
Required: true
The handlebars instance with which to register the partials

dynamicPartials

Type: Object
Required: true
Key/Value pairs that define the name of the dynamic partial, and the location relative to startingLocation

startingLocation

Type: String
Required: true
Default: .
Path to start looking for the partial templates

License

MIT License © 2021, Springer Nature

Package Sidebar

Install

npm i @springernature/util-dynamic-partial

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

8.46 kB

Total Files

11

Last publish

Collaborators

  • ndv3997
  • sndigital
  • rseidelsohn
  • testingsabrina
  • roshandeorukhkar-sn
  • benjclark
  • sonniesedge
  • rlau
  • dotcode
  • joseluisbolos
  • hollsk
  • moddular
  • jpw
  • nickcall
  • howlingmad
  • davidpauljunior
  • morgaan