How an included partial insert code into parent's block?

时光总嘲笑我的痴心妄想 提交于 2019-12-24 01:45:24

问题


What I want to do is to add the scripts block in dropdown.swig added to scripts block in template.swig.
My usage pattern could be wrong. I've a working code using ejs-locals template engine but I would like to switch to swig.

Here's the code:

<!-- template.swig, to be extended -->
<body>
  <header>
    {% include "navbar.swig" %}
  </header>
  <!-- template scripts -->
  <script src="/scripts/jquery.min.js"></script>

  {% block body %}{% endblock %}

  <!-- child scripts -->
  {% block scripts %}{% endblock %}
</body>


<!-- index.swig, to be rendered-->
{% extends "template.swig" %}

{% block content %}
<div class="container row-fluid">
  body
</div> <!-- row-fluid -->
{% endblock %}


<!-- navbar.swig, to be included-->
<div class="navbar navbar-fixed-top">
    <!-- bootstrap navbar stuff -->
    <!-- ... -->

    {% if not hideDropDown %}
      {% include "dropdown.swig" %}
    {% endif %}
</div>


<!-- dropdown.swig, to be included-->
<div class="btn-group pull-right">
    <!-- bootstrap drop down menu stuff -->
    <!-- ... -->
</div>

{% block scripts %}
{% autoescape false %}
<script src="/scripts/bootstrap-dropdown.js"></script>
<script>
  $(document).ready(function() {
    $('.dropdown-toggle').dropdown();
  });
</script>
{% endautoescape %}
{% endblock %}

回答1:


We have to do multiple extends in swig, see Issue 47 (with sample code).

Can anyone shed light on whether embed tag can solve my need?



来源:https://stackoverflow.com/questions/15779284/how-an-included-partial-insert-code-into-parents-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!