这是我的代码,index.php
require_once __DIR__.'/vendor/autoload.php';
$loader = new Twig_Loader_Filesystem(__DIR__ . '/templates');
$twig = new Twig_Environment($loader);
$template = $twig->load('index.html.twig');
echo $template->renderBlock('content', ['pageTitle' => 'Hello world']);
templates/layouts/default.html.twig
中的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ pageTitle }}</title>
</head>
<body>
{% include 'partials/header.html.twig' %}
{% block content %}{% endblock %}
{% include 'partials/footer.html.twig' %}
</body>
</html>
在templates/index.html.twig
{% extends 'layouts/default.html.twig' %}
{% block content %}
<h1>This is content</h1>
{% endblock %}
我的目录:
templates/
layouts/
default.html.twig
partials/
header.html.twig
footer.html.twig
index.html.twig
它只呈现一个文字'This is content'
,并且不会加载header.index.twig
和footer.html.twig
内容。有人可以帮助我,非常感谢你!!!!!