Symfony2包含在Twig中的html中

Har*_*itz 11 html symfony twig

我正在使用Symfony2和twig开发一个用于模板的应用程序.我使用3级结构的模板.Base.html.twig,layout.html.twig和childtemplate.html.twig.问题是我试图通过使用include在下一个子模板中包含一个example.html(常见的html文件),但它无法正常工作.问题出在哪里?

{# src/Anotatzailea/AnotatzaileaBundle/Resources/views/Page/testuaanotatu.html.twig #}
{% extends 'AnotatzaileaAnotatzaileaBundle::layout.html.twig' %}

{% block title %}Testua anotatu{% endblock%}

{% block body %}
    {% include "var/www/Symfony/web/example.html" %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

Eln*_*mov 27

取决于它的位置.让我们说它在Anotatzailea/AnotatzaileaBundle/Resources/views/example.html.twig; 然后你会像这样包括它:

{% include 'AnotatzaileaAnotatzaileaBundle::example.html.twig' %}
Run Code Online (Sandbox Code Playgroud)

  • 仅供参考,如果模板位于`Anotatzailea/AnotatzaileaBundle/Resources/views/subfolder/example.html.twig`中,则include语句必须为:`{%include'AnotatzaileaAnotatzaileaBundle:subfolder:example.html.twig'% }` (7认同)