{"id":1482,"date":"2022-08-30T15:16:54","date_gmt":"2022-08-30T15:16:54","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/23\/how-to-instantiate-the-ember-application-when-using-precompiled-templates-with-grunt-ember-templates-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:54","modified_gmt":"2022-08-30T15:16:54","slug":"how-to-instantiate-the-ember-application-when-using-precompiled-templates-with-grunt-ember-templates-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-instantiate-the-ember-application-when-using-precompiled-templates-with-grunt-ember-templates-collection-of-common-programming-errors\/","title":{"rendered":"How to instantiate the Ember Application when using precompiled templates with grunt-ember-templates-Collection of common programming errors"},"content":{"rendered":"<p>(This questions is related to this one, but now I have moved to <code>grunt-ember-templates<\/code> instead of <code>grunt-contrib-handlebars<\/code>)<\/p>\n<p>I am trying to split my ember.js handlebars templates in several files, in order to make the code base more manageable. I am using <code>grunt-ember-templates<\/code>, configured as follows:<\/p>\n<pre><code>ember_templates: {\n    compile: {\n        options: {\n            templateName: function(sourceFile) {\n                return sourceFile.replace(\/app\\\/templates\\\/\/, ''); \/\/ \/scripts\/\n            }\n        },\n        files: {\n            '\/scripts\/templates.js': [\n                '\/templates\/**\/*.hbs'\n            ]\n        }\n    }\n}\n<\/code><\/pre>\n<p>This creates a <code>dist\/scripts\/templates.js<\/code> as expected, which my client is happily loading. The <code>templates.js<\/code> looks like this:<\/p>\n<pre><code>Ember.TEMPLATES[\"accounts\"] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {\n    ...\n<\/code><\/pre>\n<p>This looks fine to me: the templates are saved in <code>Ember.TEMPLATES<\/code> array, with expected keys. There is even an <code>application<\/code> key, further down the generated <code>templates.js<\/code> file:<\/p>\n<pre><code>Ember.TEMPLATES[\"application\"] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {\n<\/code><\/pre>\n<p>Which is coming from <code>templates\/application.hbs<\/code>:<\/p>\n<pre><code>\n\n\n  \n      ...\n  \n\n  {{ outlet }}\n\n\n\n\n    \n      ...\n\n<\/code><\/pre>\n<p>Still, I am getting this error when <code>templates.js<\/code> is loaded (which is actually embedded inside <code>scripts.js<\/code>, see below my <code>index.html<\/code>):<\/p>\n<pre><code>Uncaught Error: assertion failed: You specified the templateName application for , but it did not exist.\n<\/code><\/pre>\n<p>What does this criptical error mean and how can I get rid of it?<\/p>\n<p>This is my <code>Ember Application<\/code>:<\/p>\n<pre><code>this.App = Ember.Application.create({\n    LOG_TRANSITIONS: true,\n    VERSION: '1.0.0',\n    ready: function () {\n        console.log('App version: ' + App.VERSION + ' is ready.');\n    }\n});\n<\/code><\/pre>\n<p>This is my <code>ApplicationView<\/code>:<\/p>\n<pre><code>App.ApplicationView = Ember.View.extend({\n    templateName: 'application'\n});\n<\/code><\/pre>\n<p>This is my <code>index.html<\/code>:<\/p>\n<pre><code>\n\n\n\n  \n  \n    \n    \n    \n    \n    \n\n    \n    \n    \n    \n    \n    \n\n  \n  \n\n    \n\n    \n\n    \n\n      \n          <\/code><\/pre>\n<ul>\n<li><code>Prev<\/code><\/li>\n<li><code>1<\/code><\/li>\n<li><code>2<\/code><\/li>\n<li><code>3<\/code><\/li>\n<li><code>4<\/code><\/li>\n<li><code>Next<\/code><\/li>\n<\/ul>\n<pre>\n      \n    \n\n    \n    \n    \n    \n    \n    \n    \n    \n    \n\n  \n\n<\/pre>\n<ol>\n<li>\n<p><code>For the record: my problem was solved by changing the order in which the javascript files are loaded.<\/code><\/p>\n<p><code>The <code>templates.js<\/code> must be loaded <em>after<\/em> ember is loaded.<\/code><\/p>\n<p>I thought that ember needs the templates defined before loading, but this is actually completely wrong: since the templates are stored in <code>Ember.TEMPLATES<\/code>, ember must be loaded <strong>before<\/strong> the templates are. Then the templates can be loaded, and then the application can be created.<\/p>\n<p>The reason why I did not find this bug before is that ember is not complaining at all in the console.<\/p>\n<\/li>\n<li>\n<p>I&#8217;ve been using <code>template:<\/code> instead of <code>templateName:<\/code>, and it seems to work fine:<\/p>\n<pre><code>template: Ember.TEMPLATES['application']\n<\/code><\/pre>\n<p>There may be a better way to do this. But this will at least get you unstuck.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-23 09:50:05. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>(This questions is related to this one, but now I have moved to grunt-ember-templates instead of grunt-contrib-handlebars) I am trying to split my ember.js handlebars templates in several files, in order to make the code base more manageable. I am using grunt-ember-templates, configured as follows: ember_templates: { compile: { options: { templateName: function(sourceFile) { return [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1482","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1482"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1482\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}