# @springernature/util-dynamic-partial

> Dynamically reference handlebars partials

Latest version **0.1.0** (published 2022-01-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @springernature/util-dynamic-partial
pnpm add @springernature/util-dynamic-partial
yarn add @springernature/util-dynamic-partial
bun add @springernature/util-dynamic-partial
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-01-06 |
| First published | 2021-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 8.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ajk |
| Maintainers | benjclark, sonniesedge, rlau, dotcode, joseluisbolos, hollsk, moddular, jpw, nickcall, howlingmad, sndigital, davidpauljunior, morgaan, nasiamakryg |
| Keywords | springernature, handlebars |

## Links

- npm: https://www.npmjs.com/package/@springernature/util-dynamic-partial
- Repository: https://github.com/springernature/frontend-toolkit-utilities
- Homepage: https://github.com/springernature/frontend-toolkit-utilities#readme
- Issues: https://github.com/springernature/frontend-toolkit-utilities/issues
- npm.io page: https://npm.io/package/@springernature/util-dynamic-partial

## Dependencies (5)

- [handlebars](https://npm.io/package/handlebars.md) ^4.4.3
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.15.5
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.15.4
- [@babel/plugin-transform-runtime](https://npm.io/package/@babel/plugin-transform-runtime.md) ^7.15.8
- [@springernature/util-cli-reporter](https://npm.io/package/@springernature/util-cli-reporter.md) ^2.0.0

## Alternatives

- [persona-harness](https://npm.io/package/persona-harness.md) — 4.7K weekly downloads
- [@tsparticles/effect-bubble](https://npm.io/package/@tsparticles/effect-bubble.md) — 4.6K weekly downloads
- [f3d](https://npm.io/package/f3d.md) — 730 weekly downloads
- [spark-html-motion](https://npm.io/package/spark-html-motion.md) — 298 weekly downloads
- [cra-template-particles-typescript](https://npm.io/package/cra-template-particles-typescript.md) — 227 weekly downloads

## Recent versions

- 0.1.0 (latest) — 2022-01-06
- 0.0.2 — 2021-12-14
- 0.0.1 — 2021-10-25

## README

# Dynamic Partials

[![NPM version][badge-npm]][info-npm]
![MIT License][badge-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`**
```json
{
  "dynamicPartials": {
    "partialName": "./path/to/partialName.hbs"
  }
}
```

**Javascript**
```js
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)**
```handlebars
<h2>Include the dynamic partial below</h2>
{{> partialName }}
```

> Find a more complete example in [the demo folder](./demo/README.md).

## API

### registerDynamicPartials(Handlebars, dynamicPartials, startingLocation)

Return: `Promise`<br/>
Register any number of [handlebars partial files](https://handlebarsjs.com/guide/partials.html) as defined within a JSON object

### options

#### Handlebars

Type: `Object`<br/>
Required: `true`<br/>
The handlebars instance with which to register the partials

#### dynamicPartials
Type: `Object`<br/>
Required: `true`<br/>
Key/Value pairs that define the name of the dynamic partial, and the location relative to `startingLocation`

#### startingLocation
Type: `String`<br/>
Required: `true`<br/>
Default: `.`<br/>
Path to start looking for the partial templates

## License

[MIT License][info-license] &copy; 2021, Springer Nature

[info-npm]: https://www.npmjs.com/package/@springernature/util-dynamic-partial
[badge-npm]: https://img.shields.io/npm/v/@springernature/util-dynamic-partial.svg
[info-license]: https://github.com/springernature/frontend-toolkit-utilities/blob/master/LICENCE
[badge-license]: https://img.shields.io/badge/license-MIT-blue.svg

---
_Source: https://npm.io/package/@springernature/util-dynamic-partial · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
