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?
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.
Try this:
$.each(Template, function(template) {
if(template.startsWith("_")){
// Assuming user defined templates do not start with a "_"
return true;
}
Template[template].rendered = defaultRenderingFunction;
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.