2016-12-24 39 views
0

Nunjucks使用getTemplate()预加载和异步模板预紧预编译模板 -与Nunjucks

env.getTemplate('page.html', true); 

文档也说:“如果使用任何异步加载器,则必须使用异步API。”但没有任何代码示例。任何人都可以告诉用什么来代替getTemplate来进行异步预加载?

回答

0

从自己的文件:Just add an async: true property to your loader and it will be used asynchronously.

https://mozilla.github.io/nunjucks/api.html#asynchronous

var MyLoader = nunjucks.Loader.extend({ 
    async: true, 

    getSource: function(name, callback) { 
     // load the template 
     // ... 
     callback(err, res); 
    } 
});