{"id":3277,"date":"2014-03-21T20:21:47","date_gmt":"2014-03-21T20:21:47","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/21\/compiled-template-reference-is-undefined-when-calling-dust-loadsource-in-browser-collection-of-common-programming-errors-2\/"},"modified":"2014-03-21T20:21:47","modified_gmt":"2014-03-21T20:21:47","slug":"compiled-template-reference-is-undefined-when-calling-dust-loadsource-in-browser-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/21\/compiled-template-reference-is-undefined-when-calling-dust-loadsource-in-browser-collection-of-common-programming-errors-2\/","title":{"rendered":"Compiled template reference is undefined when calling dust.loadSource() in browser-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to render HTML using compiled templates with dust.js in a browser (not server-side with node.js). If I compile the template in the client-side javascript, it works fine. If I pre-compile the template and include it as a script tag as recommended, the dust.loadSource statement results in the Chrome debugger saying: &#8220;Uncaught ReferenceError: nowork is not defined&#8221;, where &#8220;nowork&#8221; is the template name. So&#8230;<\/p>\n<p>This HTML and script works:<\/p>\n<pre><code>\n\n\n    \n    This Works\n    \n    \n\n\n    \n    \n        var templateKey = 'works';\n        var myView = {\"people\":[{\"name\":\"Fred\"},{\"name\":\"Harry\"},{\"name\":\"Linda\"},{\"name\":\"Mary\"}]};\n\n        dust.loadSource(dust.compile(\"{#people}<br \/>{name}{\/people}\", templateKey));\n        dust.render(templateKey, myView, function(err, out) {\n            $('#bingo').html(out);\n        });\n    \n\n\n<\/code><\/pre>\n<p>But this doesn&#8217;t:<\/p>\n<pre><code>\n\n\n    \n    This Doesn't Work\n    \n    \n    \n\n\n    \n    \n        var templateKey = 'nowork';\n        var myView = {\"people\":[{\"name\":\"Fred\"},{\"name\":\"Harry\"},{\"name\":\"Linda\"},{\"name\":\"Mary\"}]};\n\n        dust.loadSource(templateKey);\n        dust.render(templateKey, myView, function(err, out) {\n            $('#bingo').html(out);\n        });\n    \n\n\n<\/code><\/pre>\n<p>Where the included nowork.js file contains:<\/p>\n<pre><code>(function() {\n    dust.register(\"nowork\", body_0);\n\n    function body_0(chk, ctx) {\n        return chk.section(ctx.get(\"people\"), ctx, {\n            \"block\": body_1\n        }, null);\n    }\n    function body_1(chk, ctx) {\n        return chk.write(\"<br \/>\").reference(ctx.get(\"name\"), ctx, \"h\");\n    }\n    return body_0;\n})();\n<\/code><\/pre>\n<p>Can anyone help?<\/p>\n<p>I just realized, that this may be due to these files not being served on a machine with node.js installed. I&#8217;m actually working locally on my desktop machine. Is that it?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to render HTML using compiled templates with dust.js in a browser (not server-side with node.js). If I compile the template in the client-side javascript, it works fine. If I pre-compile the template and include it as a script tag as recommended, the dust.loadSource statement results in the Chrome debugger saying: &#8220;Uncaught ReferenceError: nowork [&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-3277","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3277","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=3277"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3277\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}