Client-side django template with jQuery

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$.extend($.template.regx, {django: /\{\{\s*([\w-]+)(?:\|([\w\.]*)(?:\:(.*?)?[\s\}])?)?\s*\}\}/g});
$.template.regx.standard = $.template.regx.django;

// test code
var template = $.template("<div>hello {{ name|substr:0,10 }}!!!</div>");
$(selector).append(template, {
    name: 'abcdefghijkl'
});

// or
var html = template.apply( {
    name: 'abcdefghijkl'
});

Comments

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.