Skip to content

Instantly share code, notes, and snippets.

@stanpalatnik
Created March 3, 2012 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stanpalatnik/1968827 to your computer and use it in GitHub Desktop.
Save stanpalatnik/1968827 to your computer and use it in GitHub Desktop.
Dust.js Client side
<html>
<head>
<script src="dust-full-0.3.0.min.js"></script>
<script type="text/javascript">
//example showing client-side compiling and rendering
var compiled = dust.compile("Hello {name}!", "index");
dust.loadSource(compiled);
dust.render("index", {name: "David"}, function(err, out) {
if(err != null)
alert("Error loading page");
//assume we have jquery
$("#pageContainer").html(out);
});
</script>
</head>
<body>
<div id="pageContainer"></div>
</body>
</html>
@angelcervera
Copy link

This code is not correct, no? You must execute after html is loaded, using, for example, $(document).ready

<title>Pruebas dustjs</title> <script src="core/library/dust/dust-full-1.1.1.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { var compiled = dust.compile("Hello {name}!", "index"); dust.loadSource(compiled); dust.render("index", { name : "David" }, function(err, out) { if (err != null) { alert("Error loading page"); } $("#pageContainer").html(out); }); }); </script>

@angelcervera
Copy link

This code is not correct. You must execute after html is loaded, using, for example, $(document).ready

@angelcervera
Copy link

This code is not correct, no? You must execute after html is loaded, using, for example, $(document).ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment