0

之前的问题似乎都没有任何信息,大约一天半的随机谷歌搜索结果一无所获。

我想要做的是,我有一个 base.html.twig 模板,然后是一个包含几个 ui 元素(幻灯片、导航菜单等)的文件夹。我应该能够做到这一点的想法:

page.html.twig 包含

{% extends 'OnMyLemonCommonBundle::base.html.twig' %}

{% block content %}

  {% include 'OnMyLemonCommonBundle::features.html.twig' %}

  {% block features %}

    <h2>Featured Articles</h2>

    <li><a href="#">Article 1</a></li>
    <li><a href="#">Article 2</a></li>

  {% endblock %}

{% endblock %}

features.html.twig 包含

<div class="row">
  <div class="large-12 columns">
    <div class="row">

      <div class="large-4 small-6 columns">
        {% block features %}{% endblock %}
      </div>

      <div class="large-4 small-6 columns">
        {% block blogs %}{% endblock %}
      </div>

      <div class="large-4 small-12 columns">
        {% block pictures %}{% endblock %}
      </div>

    </div>
  </div>
</div>

问题是这将呈现如下:

// Content from top of base.html.twig

<div class="row">
  <div class="large-12 columns">
    <div class="row">

      <div class="large-4 small-6 columns">
      </div>

      <div class="large-4 small-6 columns">
      </div>

      <div class="large-4 small-12 columns">
      </div>

    </div>
  </div>
</div>

<h2>Featured Articles</h2>

<li><a href="#">Article 1</a></li>
<li><a href="#">Article 2</a></li>

// Content from bottom of base.html.twig

问题是我如何使这个输出如下:

// Content from top of base.html.twig

<div class="row">
  <div class="large-12 columns">
    <div class="row">

      <div class="large-4 small-6 columns">

        <h2>Featured Articles</h2>

        <li><a href="#">Article 1</a></li>
        <li><a href="#">Article 2</a></li>

      </div>

      <div class="large-4 small-6 columns">
      </div>

      <div class="large-4 small-12 columns">
      </div>

    </div>
  </div>
</div>

// Content from bottom of base.html.twig
4

2 回答 2

1

您可以通过在树枝文件中添加额外的继承层来实现这一点,例如:

features-base.html.twig 包含:

{% extends 'OnMyLemonCommonBundle::base.html.twig' %}

{% block content %}

  {% include 'OnMyLemonCommYonBundle::features.html.twig' %}

{% endblock %}

page.html.twig 包含:

{% extends 'OnMyLemonCommonBundle::features-base.html.twig' %}

{% block features %}

  <h2>Featured Articles</h2>

  <li><a href="#">Article 1</a></li>
  <li><a href="#">Article 2</a></li>

{% endblock %}
于 2013-05-09T19:02:36.130 回答
0

我认为这是不可能的,但是您可以尝试使用以下方法

{% render'bundle:Controller:method' %}

你在哪里渲染它

<div class="row">
  <div class="large-12 columns">
    <div class="row">

      <div class="large-4 small-6 columns">
          {{ features }}
      </div>

      <div class="large-4 small-6 columns">
      </div>

      <div class="large-4 small-12 columns">
      </div>

    </div>
  </div>
</div>

我希望这是您的问题的解决方案

于 2013-05-08T16:55:53.733 回答