Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including handlebars-require with all npm packages installed. Try it out:

var handlebarsRequire = require("handlebars-require")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

handlebars-require v0.1.1

a helper that inject helper components into a template

Require Helper

Require helper allows for including ephemeral or "components" into your application. Right now it is mostly a experiment to see if this typeof data into Handlebar templates. The api is a bit rough right now but that should be ephemeral as well.

Usage

To get the helper injected into your instance of Handlebars require in the module and pass it the current require function and Handlebars.

var 
  Handlebars = require('handlebars');

require('handlebars-require')(require, Handlebars); 
// now you should have the require helper

In the template now you can do this.

{{require './path/to/component'}} {{!-- This is a referance to a js file --}}
<div class="component-container">
  {{MyComponent property=value}} {{!-- exported value is based of contructor.name --}}
</div>

Setting ephemeral helper name

{{require './path/to/component' exports="NamedComponent"}}
{{NamedComponent property=value}} {{!-- exports changed the ref --}}

What is a Component

Right now in the simplist form a component is a contructor that has a render function. This is loosly based off of Backbone views.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free