【问题标题】:HTML outside of block in inheriting layout继承布局中块外的 HTML
【发布时间】:2013-10-03 13:48:10
【问题描述】:

如果我错了,请纠正我,但是不可能在继承布局的块之外使用 html 代码,对吧?

这就是我的意思

{# app/Resources/view/base.html.twig #}
<!DOCTYPE html>
......
<% block sidebar %>
<h1>...</h1>
<% endblock; %>

{# src/Acme/CoolBundle/Controller/page.html.twig #}
{% extends '::base.html.twig' %}

{% block sidebar %}
 {{ parent{} }}
 <p>Lorem ipsum bla bla.. </p> // This one  works and the paragraph is rendered
{% endblock }
<h3>Latest news</h3> // Here I get A template that extends another one cannot have a body in...

【问题讨论】:

  • 您需要为您的最新新闻部分添加另一个(空)块到您的 base.html.twig。您可以为可选内容添加任意数量的占位符块到您的基础 - 继承页面只需填写他们需要的内容。

标签: php html symfony twig template-engine


【解决方案1】:

你是对的(这次 ;))。在扩展其他模板的模板中,不能将 html 放在块之外。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-07
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多