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

问题描述 投票:0回答:1

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

加载错误../resources/views/main/index.twig:未定义模板“../layouts/base.index.twig”(TwigBridge \ Twig \ Loader:查看[../layouts/base.index]而不是发现。)在“../resources/views/main/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 %}
laravel templates twig
1个回答
0
投票

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

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

所以我建议改变它:

  1. 将基本文件重命名为base-index.twig
  2. 将您的extends指令更改为:{% extends layouts.base-index %}
© www.soinside.com 2019 - 2024. All rights reserved.