injectify-view
v2.2.11
Published
Injectify marionette view into template
Downloads
4
Readme
Injectify view helper
Additional helper for handlebars, include marionette
or backbone
views into template and inject it to parent LayoutView.
Install
npm install --save-dev injectify injectify-view
Usage
Configure gulp
:
var gulp = require("gulp"),
browserify = require("browserify"),
source = require("vinyl-source-stream"),
require("injectify-view/inject");
gulp.task('js', function () {
var bundleStream = browserify('./src/index.spec.js')
.transform(require("injectify"))
.bundle();
return bundleStream
.pipe(source('index.spec.js'))
.pipe(gulp.dest('dist'));
});
If Marionette
defined globally you need to do nothing. Elsewhere:
// configure helper
require("injectify-view/marionette").setInstance(require("backbone.marionette"));
In file ./src/index.spec.js
require injectify view
helper:
require("injectify-view");
Now you can use view
helper in your templates. For example define layout:
var Layout = Marionette.Layout.extend({
template: require("./tpl/Layout.hbs")
});
and template
Layout with internal view: {{view "../Internal" "test" model=user someOption=123}}
Attributes of view helper:
1. Path to module with Backbone.View or Marionette.View
2. Name of region, that will appear on parent Layout. Optional.
It will generate unique name for you
3. Hash will be pass to view constructor, you can specify options and models in it
In Layout
will be created test
region and view will be putted in.
view
helper works like original browserify require
. You can require modules relative to template file or
node_modules
directory.
Changelog
v2.2
- Change method of internal content render, can be BC for some projects
v2.1
- Allow minor version updates of dependencies
v2.0
- Handlebars 3
- Injectify 2