Skip to content

Instantly share code, notes, and snippets.

@malev
Created March 3, 2012 18:18
Show Gist options
  • Save malev/1967225 to your computer and use it in GitHub Desktop.
Save malev/1967225 to your computer and use it in GitHub Desktop.
2nd mustach example
var helpers = {
truncate: function (str) {
if (str.length > 400) {
return str.slice(0, 400) + "...";
} else {
return str;
}
}
}
var template = "<div class='description'>{{#truncate}}{{item.description}}{{/truncate}}</div>";
// items tiene más información
items.truncate = function () {
return helpers.truncate;
};
$("#undiv").html(Mustache.render(template, items);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment