-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic.js
39 lines (35 loc) · 1.01 KB
/
dynamic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var Template = Blaze.Template;
/**
* @isTemplate true
* @memberOf Template
* @function dynamic
* @summary Choose a template to include dynamically, by name.
* @locus Templates
* @param {String} template The name of the template to include.
* @param {Object} [data] Optional. The data context in which to include the
* template.
*/
Template.__dynamicWithDataContext.helpers({
chooseTemplate: function (name) {
return Blaze._getTemplate(name, function () {
return Template.instance();
});
}
});
Template.__dynamic.helpers({
dataContextPresent: function () {
return _.has(this, "data");
},
checkContext: function () {
if (! _.has(this, "template")) {
throw new Error("Must specify name in the 'template' argument " +
"to {{> Template.dynamic}}.");
}
_.each(this, function (v, k) {
if (k !== "template" && k !== "data") {
throw new Error("Invalid argument to {{> Template.dynamic}}: " +
k);
}
});
}
});