TwigBridge扩展基础模板无法正常工作

时间:2017-12-21 03:21:32

标签: laravel templates twig

我使用TwigBridge因为我更喜欢使用Twig而不是刀片。问题是扩展基础模板会返回错误。

  

加载../resources/views/main/index.twig:模板时出错   “../layouts/base.index.twig”未定义(TwigBridge \ Twig \ Loader:   查看[../layouts/base.index]未找到。)in   “../资源/视图/主/ index.twig”

我尝试过像这样扩展模板,但它无效:

  

{%extends'../layouts/base.index.twig'%}

     

{%extends'../layouts/base.index'%}

这是资源/视图结构:

View Structure

以下是视图文件的内容: base.index.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">

    <title>Laravel</title>

    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="{{ asset('css/bundle.css') }}">
</head>
<body>

{% block content %}

{% endblock %}


<script src="{{ asset('js/bundle.js') }}"></script>
</body>
</html>

这是index.twig

{% extends '../layouts/base.index.twig' %}

{% block content %}

<div class="page-header text-center my-5"> <h1>Laravel Todo App</h1> </div>
<div class="float-right pb-3 pr-3">
    <button class="btn btn-primary"> Add todo </button>
</div>
<table class="table table-hover">
    <thead>
    <tr>
        <th scope="col">#</th>
        <th scope="col">Todo</th>
        <th scope="col">Description</th>
        <th scope="col">Deadline</th>
        <th scope="col">Status</th>
        <th scope="col">Action</th>
    </tr>
    </thead>
    <tbody>

    </tbody>
</table>


{% endblock %}

1 个答案:

答案 0 :(得分:0)

TwigBridge将点表示法解释为目录路径,并查找相对于views目录的模板。我不确定是否有办法在你的文件名中使用额外的句号,但是建议快速解决这个问题就是删除它,这样TwigBridge就不会感到困惑。

您也不需要../目录遍历 - 您只需要指定相对于views目录的路径。

所以我建议改变它:

  1. 将基本文件重命名为 base-index.twig
  2. 将您的extends指令更改为:{% extends layouts.base-index %}
相关问题