How to resolve conflict between Embers Handlebar and Django Template

偶尔善良 提交于 2019-12-24 05:54:54

问题


I am using Ember and Django and quickly found out that the template delimiter in Handlebar conflicts with that of Django Templates.

So i intsalled Django-embers http://pypi.python.org/pypi/django-ember/0.1

But It just not seem to work properly. This is the problem:

If I have something like this in APP.js

var Ab = Em.Application.create({
  appDescription : 'HelloWorldApp'
});

I can easily render it in the template like this

{% load ember %}
{% handlebars "" %}
    {{Ab.appDescription}}
{% endhandlebars %}

This works. But when I try using the Template Tags eg {{#each}} things fail. For example I had this in APP.js

Songs.songsController = Ember.ArrayController.create({
    content: [],
    init: function(){
        // create an instance of the Song model
        var song = Songs.Song.create({
            title: 'Son of the Morning',
            artist: 'Oh, Sleeper',
            genre: 'Screamo'
        });
        this.pushObject(song);
    }
});

And try to Rendeer it with:

{% load ember %}
{% handlebars "" %}
{{#each Songs.songsController}}
        <h3>{{title}}</h3>
        <p>{{artist}} - {{genre}}</p>
{{/each}}
{% endhandlebars %}

Nothing gets outputed!

And it has nothing to do with my code because I moved the template and JS file outsite django and tested the code, it works as expected then.

Do tell what is going wrong here!


回答1:


The init function is the constructor of all Ember objects. Basically, in order to put in place all bindings/observers stuff when creating an object, the constructors of the class hierarchy must be called when overriding the contructor. In fact, this is just like you will do it in others programming languages.



来源:https://stackoverflow.com/questions/13357697/how-to-resolve-conflict-between-embers-handlebar-and-django-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!