npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@financial-times/x-handlebars

v14.7.7

Published

This module provides Handlebars helper functions to render `x-dash` component packages or local compatible modules within existing Handlebars templates.

Downloads

663

Readme

x-handlebars

This module provides Handlebars helper functions to render x-dash component packages or local compatible modules within existing Handlebars templates.

Installation

This module is supported on Node 12 and is distributed on npm.

npm install -S @financial-times/x-handlebars

To use the x-handlebars helper in your application views you must first register it with Handlebars. To do this you can use the registerHelper method, providing a helper name as the first argument (we recommend x) and calling the xHandlebars function:

const xHandlebars = require('@financial-times/x-handlebars');
const handlebars = require('handlebars');

handlebars.registerHelper('x', xHandlebars());

If you are building an Express app using n-ui you can register the helper functions on application startup. Please note that if you are already registering helpers then you may need to merge your existing configuration:

const xHandlebars = require('@financial-times/x-handlebars');
const express = require('@financial-times/n-ui');

const app = express({
	helpers: {
		x: xHandlebars()
	}
});

An options object may be provided to the xHandlebars function when called. The options and their defaults are shown below:

xHandlebars({
	baseDirectory: process.cwd()
});

This module will install the x-engine module as a dependency to perform the rendering of x- components. Please refer to the x-engine documentation to setup your application with x-engine.

Usage

This package provides a single helper function able to load x-dash component packages or local compatible modules.

Installed packages will be loaded from the @financial-times scope and are specified using the package argument.

Local modules are resolved relative to the configured base directory and are specified using the local argument.

If a module has multiple named exports then the specific property to use may be specified with the component argument.

For example, to render a teaser component from the x-teaser package:

<div class="teaser-container">
	{{{x package="x-teaser" component="Teaser"}}}
</div>

Or to load a local module with a default export:

<div class="promo-box-container">
	{{{x local="components/promo"}}}
</div>

Note, that you should use the triple mustache syntax, {{{, to ensure the HTML returned by the helper is not escaped.

The included component will inherit the current Handlebars context. Any extra arguments will be merged into the context, providing an easy means to provide overrides in-situ:

<div class="teaser-container">
	{{{x package="x-teaser" component="Teaser" showStatus=false}}}
</div>