1

I have few questions on partials and overriding templates. For that i used the following folder structure.

projectRoot

   dust-core-0.6.0.min.js
   jquery.js
   test.html
   partial.tl
   main_without_override.tl

The content of partial.tl:

{+greeting} Hola {/greeting}

{+world} World {/world}

The content of main_without_override.tl:

{>partial/}

The content of test.html:

<!DOCTYPE html>
<html>
  <head>
    <script src="dust-core-0.6.0.min.js" type="text/javascript"></script>
    <script src="jq.js" type="text/javascript"></script>
  </head>
  <body>
  </body>
  <script>
    $.get('main_without_override.tl', function(){
        console.log(arguments);
    })
  </script>
</html>

In the index.html when i try to get the main_without_override.tl its saying 404. But im sure that the file is there. The path that firebug is showing is correct.But browser says 404.

I want to know

  1. How to get this main_without_override.tl
  2. Apply templating for main_without_override.tl and render in the browser.

I searched in google most of the examples give only the syntax. Can somebody help me in rendering the main_without_override.tl template.

Rajkamal Subramanian
  • 6,884
  • 4
  • 52
  • 69
  • u have to add more info. why are u trying to get the partial with a request? what are you using as server? what is the request path? – JAiro Jan 25 '13 at 14:16

2 Answers2

1

In order to compile templates on the client (which is probably not a really good idea), you need to include dust-full instead of dust-core. This is because dust-core does not include the Dust compiler.

The reason that compiling templates on the client is probably not a good idea is that Dust compiles to JavaScript and as @monshi mentioned, you can compile the templates and then serve them as JavaScript. It is possible to get .tl files through AJAX if you include dust-full, but it is a better idea to compile that template beforehand and then make a dynamic request for that .js file when you need.

smfoote
  • 5,449
  • 5
  • 32
  • 38
0

You can include your dust template as a JavaScript file by using <script> tag, but you need to compile it first, which is explained here

Then add following templates (scripts) to test.html:

    <script type="text/javascript" src="partial.js"></script>
    <script type="text/javascript" src="main_without_override.js"></script>

And in you JavaScript render the template by dust.render method:

    dust.render('main_without_override', your_json_object, function(err, out){

        your_dom_element.innerHTML = out;

    });

Related question: how to use dustjs-linkedin as client side templating?

Community
  • 1
  • 1
Omid Monshizadeh
  • 1,514
  • 1
  • 10
  • 12
  • This answered my question. Can you also let me know if its possible to get `.tl` files through ajax. I'm getting `404` error while trying to get '.tl` files. From the dust js site i came to know that if i need to compile the templates in browser in need to include a complier js. I included the complier script, by doing so i get an js error `AST.parse` is not a function. Thanks for your time. – Rajkamal Subramanian Jan 26 '13 at 22:17
  • Are you trying to do this using a file: protocol? You must use http: – Steve H. Jan 31 '13 at 03:52