javascript - Handlebars does not output anything -
at start of file define handlebars etc.:
<!-- build:js(.) scripts/vendor.js --> <!-- bower:js --> <script src="bower_components/jquery/dist/jquery.js"></script> <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script> <script src="bower_components/handlebars/handlebars.js"></script> <!-- endbower --> <!-- endbuild --> at end of index.html-file pull in handlebars-file:
<!-- build:js({app,.tmp}) scripts/main.js --> <script src="scripts/main.js"></script> <script src="scripts/serverhandler.js"></script> <script src="scripts/driver.js"></script> <!-- endbuild --> the file handlebars-related code driver.js. looks this:
driver = { someboolean : false, name : null, starttime: new date(), position : null }; source = $('#drive-buttons-template').html(); template = handlebars.compile(source); template(driver); the template in index.html-file, , between loading of handlebars.js-file, , files:
<script id="drive-buttons-template" type="text/x-handlebars-template"> <button type="button" class="btn btn-default btn-lg"> {{#if someboolean}} <span class="glyphicon glyphicon-stop" aria-hidden="true"></span> start {{else}} <span class="glyphicon glyphicon-play" aria-hidden="true"</span> stop {{/if}} </button> </script> i've tried compiling on tryhandlebars, , works there, makes me think have wrong in setup. when load page, gives me no errors, not show either. can use handlebars-methods etc. console, doesn't change anything.
hopefully isn't me having missed essential, may be. appriciated. in advance!
update: experimenting in console: can access template, driver , source. call template(driver) returns right html, website isn't updated.
it may not have been clear, use grunt local development environment, , handlebars installed bower. gruntfile produced yeoman.
i found solution last line of this jsfiddle. gave tag template id, , used:
$('#tagidname').append(template(driver)); instead of template(driver);
Comments
Post a Comment