简体   繁体   中英

Asynchronous re-rendering with Nunjucks

I use precompiled template files which are rendered synchronously, and I want to re-render blocks of data in those templates. Is this possible and if so, how is this best done?

An example:

<div>
    <h1>{{ synchronousTitle }}</h1>

    {% block aSyncAjaxData %}
        <div>
            <h1>Search for {{ phrase }}</h1>

            <div class="results">
                {% for result in searchResults %}
                    <div class="result">
                        ... Loop album results
                    </div>
                {% endfor %}
            </div>
        </div>
    {% endblock %}
</div>

The block ajaxData is rendered empty first (which works using the block tag), and should be re-rendered with asynchronous data.

在Nunjucks的最新版本中,可以使用编写异步加载程序和扩展程序的异步渲染,请参见: http ://mozilla.github.io/nunjucks/api.html#asynchronous

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM