I have used templates using underscore using this tutorial. http://backbonetutorials.com/what-is-a-view/
I have a situation where I just want to add some text in a p tag to a div structure. This is not a template just some text that needs to have some values injected into it. Is there a way to use underscore to just updated the variables in this text. Or would I need to create the text as a template and then add the template using html(_template)
<div id="popup">
<p>I want to add some text in here <%=variable1%>, Then add another variable text in here <%=variable2%></p>
</div>
UPDATE:
I tried doing it based off the template docs using this code.
<html>
<head>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/underscore.js"></script>
<script type="text/javascript" src="js/core.js"></script>
</head>
<body>
<div id="popup">
<div id="template_holder"></div>
</div>
<!-- TEMPLATES FOR CANCEL PAYMENT MODEL -->
<script type="text/template" id="card-success_tmp">
<p>I want to add some text in here <%=variable1%>, Then add another variable text in here <%=variable2%></p>
</script>
</body>
</html>
Then in my core js file I have this code below inside a click event that launches my popup
var variables = {variable1:'[xxxx]', variable2:'[MM/YY]'};
var template = _.template( $("#card-success_tmp").html(), variables );
$('#popup #template_holder').html(template);
But the above is still not working.
I have even tried
var template = _.template( $("#card-success_tmp").html() );
$('#popup #template_holder').html(template({variable1:'[xxxx]', variable2:'[MM/YY]'}));
It renders the text but the passed in variables do not get rendered.
If I added the template as a string and not from the script tag then it will work. The question is why is it not working from the script tag. It renders the text but not the variables passed into it.
var template = _.template( "<p>I want to add some text in here <%=variable1%>, Then add another variable text in here <%=variable2%></p>" );
$('#popup #template_holder').html(template({variable1:'[xxxx]', variable2:'[MM/YY]'}));