Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 250
andrew.fox Avatar asked Oct 04 '12 20:10

andrew.fox


1 Answers

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.

like image 85
smfoote Avatar answered Nov 16 '22 07:11

smfoote