我正在关注symfony2框架的教程..
我已经设法渲染一个继承自基本布局的模板,如下所示
# ::layout.html.twig > MyvendorBlogBundle:blog:index.html.twig
# then inside the controller action, call
$this->render('MyvendorBlogBundle:Blog:index.html.twig', ['foo'=>'bar']);
我决定在两者之间添加一个中间模板,但是我很难制作树枝模板引擎来渲染我的3个布局级联模板:如上所述,我无法使用以下是schem,而是一个空白页面(没有引发异常,源代码只包含base.html.twig代码)
# ::layout.html.twig > MyvendorBlogBundle::layout.html.twig > MyvendorBlogBundle:blog:index.html.twig
这是我的模板
base(app / Ressources / views):
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Welcome!{% endblock %}</title>
{% block stylesheets %}{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>
<div id="app-container">
<header id="app-header">
</header>
<div id="app-page-content">
{% block body %}{% endblock %}
</div>
</div>
{% block javascripts %}{% endblock %}
{# FLASH BAG HANDLING #}
{% for label, flashes in app.session.flashbag.all %}
{% for flash in flashes %}
<div class="alert alert-{{ label }}">
{{ flash }}
</div>
{% endfor %}
{% endfor %}
</body>
</html>
然后博客包布局(src / Myvendor / BlogBundle / Resources / views):
{% extends "::base.html.twig" %}
{% block body %}
{% block side %}
<div id="blog-side">
<nav>
<a href="#">1rst link</a>
</nav>
</div>
{% endblock %}
{% block main %}{% endblock %}
{% endblock %}
现在索引页面模板(src / Myvendor / BlogBundle / Resources / views / Blog):
{% extends "MyvendorBlogBundle::layout.html.twig" %}
{% block main %}
<h1>{{ caption }} !</h1>
{% if caption is not empty %}
{{ caption }}
{% endif %}
{% endblock %}
最后是控制器
namespace Myvendor\BlogBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class BlogController extends Controller
{
public function indexAction()
{
return $this->render('MyvendorBlogBundle:Blog:index.html.twig', ['caption'=>'hello!']);
}
}
有人能看到这里发生了什么吗?
pb可能很明显,但我现在已经卡住了几个小时,阻塞嵌套对我来说似乎很完美:/