ember.js - Loading Handlebars from Javascript -
i writing emberjs project in want load handlebars templates javascript instead of creating them in html file.
here's code like:
<body> <script type='text/x-handlebars' data-template-name='template1'> ... </script> <script type='text/x-handlebars' data-template-name='template2'> ... </script> <script type='text/x-handlebars' data-template-name='template3'> ... </script> <body> however, using requirejs maintain project modular , want able load template through .js file
i've checked out handlebars.compile(source) call, doesn't template registered name, emberjs code, able access. also, please share insights on keeping emberjs projects modular.
before reply - if new ember project, please utilize ember app kit or new ember-cli. we're using template loading:
define({ requiretemplate: function (url, name) { $.ajax({url: url, async: false, success: function(templatetext) { var compiledtemplate = ember.handlebars.compile(templatetext); ember.templates[name] = compiledtemplate; } }); } }) and using iterate on templates (which can serialised directory). keeping project modular - again, please utilize either ember app kit or ember-cli.
javascript ember.js handlebars.js
No comments:
Post a Comment