简体   繁体   English

是否可以“串联”来自子级和父级龙卷风模板的块?

[英]Is it possible to “concatenate” blocks from child and parent Tornado templates?

I have a few templates like this: 我有一些这样的模板:

base.html base.html

<script src="/js/jquery.js"></script>
{% block scripts %}
{% end %}

blog-base.html blog-base.html

{% extends base.html %}
{% block scripts %}
    <script src="/js/blog-base.js"></script>
{% end %}

blog-article.html blog-article.html

{% extends blog-base.html %}
{% block scripts %}
    <script src="/js/blog-article.js"></script>
{% end %}

I would like to have all three scripts included in the final product, but of course the above code won't do that, instead opting to replace blog-base.html's script block with the one in blog-article.html. 我希望最终产品中包含所有三个脚本,但是上述代码当然不会这么做,而是选择用blog-article.html中的一个替换blog-base.html的script块。 Is there any way, besides setting up a separate block name, to make this work? 除了设置单独的块名称之外,还有什么方法可以使这项工作有效? I imagined something like this for blog-article.html 我为blog-article.html设想了这样的事情

{% extends base.html %}
{% block scripts %}
    <script src="/js/blog-base.js"></script>
    {% render-block scripts %}
    {% end %}
{% end %}

to have it both render the child template's scripts block and define a block for the parent base.html to use, but I have my doubts that such a thing exists. 使其呈现子模板的scripts为父base.html定义要使用的块,但是我怀疑这样的事情是否存在。

It's not currently possible (and difficult to implement with the way Tornado templates currently work). 目前尚不可能(并且很难用Tornado模板当前的工作方式实现)。 For the particular case of adding script tags you might be able to use UIModules (which have special support for adding scripts or css links to the current page) instead of extending a base template. 对于添加脚本标签的特殊情况,您可以使用UIModules(它对将脚本或CSS链接添加到当前页面具有特殊支持)而不是扩展基本模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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