1

I'm attempting test a simple client-side render with a pre-compiled dust template, but when I attempt to render, dust complains that it can't find my template:

[DUST WARN]: Chunk error [Error: Template Not Found: basicName] thrown. Ceasing to render this template. 

My page looks like this:

<!DOCTYPE html>
<html lang="en-US">
<head>
    <script type="text/javascript" src="dust-full-2.4.js"></script>
    <script type="text/javascript" src="basicName.js"></script>
</head>
<body>
    <div id="dustContainer"></div>
    <script>
        var json_payload = { "name": {
            "firstName" : "Brock",
            "lastName" : "Sampson"
        }};
        var dustContainerDiv = document.getElementById("dustContainer");

        dust.render("basicName", json_payload, function(err, out) {
                dustContainerDiv.innerHTML = out;
        });
    </script>
</body>
</html>

And my template file (basicName.tl):

<p>{name.firstName}</p><p>{name.lastName}</p>

Compiles to this (basicName.js):

(function(){dust.register("basicName.tl",body_0);function body_0(chk,ctx){return chk.write("<p>").reference(ctx.getPath(false, ["name","firstName"]),ctx,"h").write("</p><p>").reference(ctx.getPath(false, ["name","lastName"]),ctx,"h").write("</p>");}return body_0;})();

I've tested this same template/payload/html using client-side template compilation and everything works fine. What am I missing in order to be able to use pre-compiled templates?

josh-cain
  • 4,997
  • 7
  • 35
  • 55

1 Answers1

2

If you take a closer look at compiled dust template, there is a line of code:

... dust.register("basicName.tl", ...

This line of code adds compiled template under key "basicName.tl" into dust.cache.

Under the hood dust.render will try to find given template name in dust.cache

Code below won't work since dust won't find "basicName" template in dust.cache:

dust.render("basicName", json_payload, function(err, out) {
...

Calling it like so should work:

dust.render("basicName.tl", json_payload, function(err, out) {
...
kate2753
  • 136
  • 3