(This question is related to this one)
I have a web2py application which I want to extend with some ember.js code. The delimiters of the templating systems in web2py and ember.js conflict (both are {{
and }}
). Since my application has no ember.js legacy, I would like to write the ember.js code using a different delimiter. Is this possible?
The template engine use by ember.js is Handlebars.js, and I don't think you can change the delimiter. I've seen the other question, and perhaps an other answer could be found here : Handlebars.js in Django templates
In web2py: response.delimiters = ('[[',']]')
If you don't want to change any delimiters (on web2py or in handlebars) you can do it by saving the handlebars template in an external file like people.hbs in the web2py /static/ folder for example
{{#each people}}
<div class="person">
<h2>{{first_name}} {{last_name}}</h2>
</div>
{{/each}}
And in the view import that file using jQuery load() function.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="https://raw.github.com/wycats/handlebars.js/master/dist/handlebars.js"></script>
<div id="list"></div>
<script id="people-template" type="text/x-handlebars-template"></script>
<script type="text/javascript">
$('#people-template').load('/static/people.hbs', function() {
var template = Handlebars.compile($("#people-template").html());
var data = {
people: [
{ first_name: "Alan", last_name: "Johnson" },
{ first_name: "Allison", last_name: "House" },
]
};
$('#list').html(template(data));
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With