I’m using backbone.js for a rails project I’ve got on the side. I’m embedding templates in the rails views using something like:
<script type="text/template" id="this-is-the-id">
... template goes here ...
... the line below this is where my error's coming from ...
<%% _(<%= aNumber %>.times(function(){ console.log('hi'); });) %>
</script>
I’m getting the error Uncaught SyntaxError: Unexpected token <. If I replace <%= aNumber %> with an integer, it works as expected. Also, if I console.log(<%%= aNumber %>), it logs the correct number.
Does anybody know how I can accomplish something like this? I know that’s kind of a sloppy way to organize my code, but this is just a quick little hack I’m putting together.
Thanks!
Turns out I didn’t need to wrap
aNumberwithin the escaping<%%=and%>, and that fixed it for me.