Skip to content
Browse files

Modify main.js to allow use of Handlebars for templates

Check if Handlebars or Mustache is present for use in templates.
If only one is present, we use that.  If both are present, we
select Mustache by default, but allow the user to override by
setting ich.useHandlebars = true.
  • Loading branch information...
1 parent 582f94b commit ff14decc3a8647073aecf28064e1cb72d62947af @achur committed
Showing with 12 additions and 1 deletion.
  1. +12 −1 source/main.js
View
13 source/main.js
@@ -34,7 +34,18 @@
ich.templates[name] = templateString;
ich[name] = function (data, raw) {
data = data || {};
- var result = Mustache.to_html(ich.templates[name], data, ich.templates);
+ // Allow either Handlebars or Mustache to be used for
+ // templates, depending on which is present. If both are
+ // present, select Mustache by default. Allow user to
+ // select Mustache when both are present by setting
+ // ich.useHandlebars to true.
+ var result;
+ if (typeof Handlebars != "undefined" && (typeof Mustache == "undefined" || ich.useHandlebars)) {
+ var handlebarsTemplate = Handlebars.compile(ich.templates[name]);
+ result = handlebarsTemplate(data, { partials: ich.templates });
+ } else if (Mustache) {
+ result = Mustache.to_html(ich.templates[name], data, ich.templates);
+ }
return (ich.$ && !raw) ? ich.$(result) : result;
};
}

0 comments on commit ff14dec

Please sign in to comment.
Something went wrong with that request. Please try again.