Handlebars.js in Django templates

前端 未结 8 1572

I need a javascript templating system and i think handlebars.js does an excellent job in this case. I\'m having syntax conflicts with handlebars templates inside a django te

8条回答
  •  死守一世寂寞
    2020-12-24 06:53

    I wrote a very small django application : django-templatetag-handlebars exactly for that purpose.

    {% load templatetag_handlebars %}
    
    {% tplhandlebars "tpl-infos" %}
        {{total}} {% trans "result(s)." %}
        

    {% trans "Min" %}: {{min}}

    {% trans "Max" %}: {{max}}

    {% endtplhandlebars %}

    Render your block as usual using Handlebars.js API :

    var properties = {
        total: 10,
        min: 5,
        max: 4
    };
    
    var template = Handlebars.compile($('#tpl-infos').html()),
        rendered = template(properties);
    

    I wrote it the day @chrisv published its package, with a KISS approach in mind. It is mainly based on Miguel Araujo's gist : https://gist.github.com/893408.

提交回复
热议问题