javascript - How to store a template in an expression in Handlebars.js? -
i want place templates on several places in dom without having write jquery expression on , on again. want place template in dom typing variable/attribute {{template}} anywhere in body.
is doable using handlebars? if not, there other way me achieve this?
you need use handlebar helpers
handlebar_helpers
p.s. dont forget use safestring else escaped default
updating answer based on ur comment link provided did give out excellent explanation. please find below example.
assume need return welcome message when name given
handlebars.registerhelper('welcome', function(name) { return new handlebars.safestring( "<p>hi "+name+", welcome stackoverflow</p>" ); });
then calling {{{welcome "sagittarius"}}}
return
hi sagittarius, welcome stackoverflow
Comments
Post a Comment