@timkendrick/ember-htmlbars-helpers
v0.1.1
Published
Ember helpers for HTMLBars
Downloads
3
Readme
ember-htmlbars-helpers
Ember helpers for HTMLBars
Installation
npm install @timkendrick/ember-htmlbars-helpers
Description
Ember templates are executed by HTMLBars, an HTML-friendly version of Handlebars.
Ember comes pre-loaded with a selection of HTMLBars helpers, however these are distributed as part of the Ember source code and cannot easily be used outside Ember apps.
This is an effort to package up some of those core helpers, allowing HTMLBars to be used productively in a non-Ember environment.
Usage
When rendering an HTMLBars template, set the helpers
property on the env
object:
var helpers = require('@timkendrick/ember-htmlbars-helpers');
var compiler = require('htmlbars/dist/cjs/htmlbars-compiler');
var hooks = require('htmlbars/dist/cjs/htmlbars-runtime').hooks;
var render = require('htmlbars/dist/cjs/htmlbars-runtime').render;
var DOMHelper = require('htmlbars/dist/cjs/dom-helper');
var source = '{{#if foo}}Helpers loaded!{{/if}}';
var data = { foo: true };
var compileOptions = {};
var template = compiler.compile(source, compileOptions);
var env = {
dom: new DOMHelper(),
hooks: hooks,
helpers: helpers
};
var result = template.render(env, scope, { contextualElement: document.body });
var dom = result.fragment;
document.body.appendChild(dom);
Included helpers
Documentation for each helper can be found in the Ember API reference.
License
Copyright (c) 2015 Yehuda Katz, Tom Dale and Ember.js contributors