有人知道我为什么会犯这个错误吗?我正在尝试将我的头文件导入到我的另一个小枝文件中。
注意:如果我删除链接,它可以正常工作。
Type: Twig_Error_Syntax
Message: A template that extends another one cannot have a body in "assessmentBuilder/FacultyControl.html.twig" at line 2.
File: /var/www/html/dev/portfolio/libraries/Twig/Parser.php
Line: 374有什么帮助吗?我阅读了Twig文档,但它似乎写得很糟糕,我无法理解为什么会发生这种情况。
{% extends "home_page_tabs.html.twig" %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../docs-assets/ico/favicon.png">
<title>Assessment for Portfolio</title>
<!-- css imports -->
<link href="/dev/editButton/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link href="/dev/editButton/css/hover.css" rel="stylesheet">
<link href="/dev/editButton/css/style_assessment.css" rel="stylesheet">
<!-- js imports -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="/dev/editButton/js/script2014.js"></script>
</head>
<body>
<!-- secondary header that appears underneath the tabs -->
<div class="page-header fluid-container">
<div class="col-md-12 text-center">
<h1>My Classes</h1>
</div>
</div>
<div class="footer">
<div class="container"><p>© ASAP Media Services 2014</p></div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="/dev/editButton/js/bootstrap.js"></script>
</body>
</html>发布于 2014-07-31 19:17:33
extends不仅仅是包含的另一个词。它做了更多的合并工作,即它接受一个父文件,并有选择地用扩展文件中定义的块(包含extends的块)替换单个块。
因此,首先用一些块定义一个基本模板。然后用extends派生这个基本模板并覆盖这些块。
看一下这个例子:http://twig.sensiolabs.org/doc/tags/extends.html
因此,错误消息表明子模板文件中的代码是block指令之外的代码。您将在这里找到解释:getting error that a template that extends can not have body
顺便说一句,小枝还有一个include指令。就在这里:
http://twig.sensiolabs.org/doc/tags/include.html
我可以想象它更适合你打算做的事情。使用include,您可以简单地将模板“链”在一起。
https://stackoverflow.com/questions/25065217
复制相似问题