Search code examples
javascriptdust.js

Dust.js with inline JavaScript


I want to create a dust.js template but with inline javascript function. It that possible? The problem is with single '{' as a template character.

For instance:

<html>
...
<body>
<script>
  function test(var) { alert('Hi {name} with ' + var); };
</script>
  Hello {name} 
</html>

Can I switch dust's special char to "{{"?

PS. I know that there's {~rb} but using it with inline JS would be a horror.


Solution

  • It works for me. Because you have parentheses, curly braces, and spaces inside of your curly braces, the content within the curly braces is not parsed as a Dust reference. Those characters are not legal characters for Dust references.

    Try it out here for LinkedIn Dust or here for akdubya Dust.