2016-12-24 8 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); 
    } 
});