Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default delimiters in ember.js

(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?

like image 812
blueFast Avatar asked Aug 26 '12 18:08

blueFast


3 Answers

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

like image 151
sly7_7 Avatar answered Sep 21 '22 01:09

sly7_7


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

like image 42
Massimo Avatar answered Sep 24 '22 01:09

Massimo


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>
like image 45
Francisco Costa Avatar answered Sep 24 '22 01:09

Francisco Costa