javascript - How to remove template markup if data is missing in Handlebars? -
how 1 remove template markup html snippet if info wasn't present.
var $target = $(target); var datastring = // json feed ! fails if( typeof datastring !== "undefined") { var info = $.parsejson(datastring); var template = handlebars.compile($target.html()); var html = template(integrationdata); $target.html(html); } else { // goes here? // making "striptags" handlebars.striptags($target.html()); }
basically want automatically strip out {{
, }}
failsafe.
handlebars ignore {{whatever}} if object not exist , removed markup.
if feed fails default empty object:
var $target = $(target); var datastring = // json feed ! fails var info = {}; if( typeof datastring !== "undefined") { info = $.parsejson(datastring); } var template = handlebars.compile($target.html()); var html = template(data); $target.html(html);
hope helps?
javascript handlebars.js
No comments:
Post a Comment