javascript - 在 Twig 文件中导入 Twig 文件

标签 javascript jquery html twig slim

有人知道为什么我会收到此错误吗?我正在尝试将我的头文件导入到我的其他 Twig 文件之一中。

注意:如果我删除扩展链接,它就可以正常工作。

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>&copy; 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>

最佳答案

extends 不仅仅是包含的另一个词。它执行更多的合并工作,即它需要一个父文件并有选择地用您在扩展文件(包含 extends 的文件)中定义的 block 替换单个 block 。

因此,首先定义一个带有一些 block 的基本模板。然后使用 extends 派生此基本模板并覆盖 block 。

看看这个例子:http://twig.sensiolabs.org/doc/tags/extends.html

错误消息表明,子模板文件中的代码位于 block 指令之外。您会在这里找到对此的解释:getting error that a template that extends can not have body

顺便说一下,TWIG 还有一个 include 指令。在这里:

http://twig.sensiolabs.org/doc/tags/include.html

我可以想象它更适合您的意图(?)。使用 include,您可以简单地将模板“链接”在一起。

关于javascript - 在 Twig 文件中导入 Twig 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25065217/

相关文章:

javascript - setPointerCapture 在 Chrome 和 Firefox 中的行为不同

javascript - 如何让JS脚本使用某些变量

javascript - jquery中刷新DataTable插件表

javascript - float 元素和使用 jQuery

javascript - Chrome 扩展程序内容脚本未注入(inject)特定网站

javascript - 如何使用jquery隐藏/显示

jquery - 在 jQuery 中引用新创建的对象最简洁的方法是什么?

php - 使用 F12 工具时信息加倍

iphone - 如何使网站适应手机和 iPad 屏幕的大小?

html - IE7 float 错误解决方法?