Reputation: 3011
I would like to execute a function for each user-defined template in Meteor.
Example:
<template name="settings">
<p>Settings</p>
</template>
Then in some JS file:
template_names = ...
_.each(template_names, function(name) {
Template[name].rendered = defaultRenderingFunction;
});
Is there some well-defined way to get the list of user-defined (not system-defined) templates?
Upvotes: 2
Views: 109
Reputation: 1631
Try this:
$.each(Template, function(template) {
if(template.startsWith("_")){
// Assuming user defined templates do not start with a "_"
return true;
}
Template[template].rendered = defaultRenderingFunction;
});
Upvotes: 1
Reputation: 3011
Going with this solution so far:
var template_names = [];
for (var key in Template) {
if (Template.hasOwnProperty(key)) {
// Meteor internal templates begin with _
if (key.indexOf('_') !== 0) {
template_names.push(key);
}
}
}
It will include templates included in other packages.
Upvotes: 2