Changing default delimiters in ember.js

(This question is related to this )

I have a web2py application that I want to extend with some ember.js code. Template system separators in web2py and ember.js conflicts (both are {{and }}). Since my application does not have the legacy of ember.js, I would like to write ember.js code using a different delimiter. Is it possible?

+5
source share
3 answers

Using the ember.js template engine is Handlebars.js, and I don't think you can change the delimiter. I saw another question, and maybe you can find another answer: Handlebars.js in Django templates

+4
source

web2py: response.delimiters = ('[[', ']]')

+3

If you do not want to change any separators (on web2py or in descriptors), you can do this by saving the handlebars template in an external file, for example, people.hbs in For example, web2py / static / folder

{{#each people}}
<div class="person">
    <h2>{{first_name}} {{last_name}}</h2>
</div>
{{/each}}

And in the view, import this file using the 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>
+1
source

All Articles