Laravel 5.3 Twig rcrowe / twigbridge 0.9.4扩展功能无法正常工作

时间:2017-02-07 13:02:51

标签: php laravel twig laravel-5.3 php-7

我在Laravel 5.3中扩展Twig模板时遇到问题

extends函数根本不起作用,我尝试了一切可能的方法来扩展我的基本模板

  

Laravel 5.3。*   Twigbridge ^ 0.9.4   OSX

为清楚起见,我刚刚创建了一个简单的例子

Folder = views /

foo.twig

Testing twigs extend function:
<br>
{% block test %}
    Extend does not work :(
{% endblock %}

bar.twig

{% extends 'foo' %} 

{% block test %}
The extend function works!
{% endblock %}

web.php

Route::get('/test', function () {
    return View::make('foo');
});

Route::get('/test2', function () {
    return View::make('bar');
});

结果: enter image description here

更新:出于某种原因,当我渲染bar.twig时,它会被正确渲染!

不幸的是,这对我的真实世界项目不起作用。 由于我使用了多个块,因此您无法扩展多个文件。 包括工作正常,我可以使用包括而不是...但是cmon让我们解决这个问题并且使用了很棒的扩展功能:)

没有例外,警告......无论如何,

我的意思是星期二,我很累但很闷,我在这里错过了一些明显的东西吗?

有关此问题或建议的调试或解决方案的任何提示吗?

我的实际项目:

我的文件夹结构:

  

视图/模板/电子邮件/ files.twig

我甚至尝试将所有内容都放在

  

视图/

我的测试路线:

Route::get('/test', function () {
    return View::make('templates.email.index',['foo'=>'foo']);
});


Route::get('/test2', function () {
    return View::make('index');
});

这不起作用:

{%  extends 'templates/email/index.twig' %}

{% block body %}
    <table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateBody">
        <tr>
            <td valign="top" class="bodyContent" mc:edit="body_content">

                {{ custom }}

            </td>
        </tr>
    </table>
{% endblock %}

也不是这样:

{%  extends 'templates.email.index' %}

{% block body %}
    <table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateBody">
        <tr>
            <td valign="top" class="bodyContent" mc:edit="body_content">

                {{ custom }}

            </td>
        </tr>
    </table>
{% endblock %}

也不是:

{%  extends 'index' %}

{% block body %}
    <table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateBody">
        <tr>
            <td valign="top" class="bodyContent" mc:edit="body_content">

                {{ custom }}

            </td>
        </tr>
    </table>
{% endblock %}

也不是,这是自动完成建议的:

{%  extends 'index.twig' %}

{% block body %}
    <table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateBody">
        <tr>
            <td valign="top" class="bodyContent" mc:edit="body_content">

                {{ custom }}

            </td>
        </tr>
    </table>
{% endblock %}

我的索引:

{% block header %}
header
{% endblock %}
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
<center>
    <table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable">
        <tr>
            <td align="center" valign="top" id="bodyCell">
                <!-- BEGIN TEMPLATE // -->
                <table border="0" cellpadding="0" cellspacing="0" id="templateContainer">
                    <tr>
                        <td align="center" valign="top">
                            <!-- BEGIN PREHEADER // -->
                            {% block preHeader %}
                                pre
                            {% endblock %}
                            <!-- // END PREHEADER -->
                        </td>
                    </tr>
                    <tr>
                        <td align="center" valign="top">
                            <!-- BEGIN BODY // -->
                            {% block body %}
                                body
                            {% endblock %}
                            <!-- // END BODY -->
                        </td>
                    </tr>
                    <tr>
                        <td align="center" valign="top">
                            <!-- BEGIN FOOTER // -->
                            {% block footer %}
                                footer
                            {% endblock %}
                            <!-- // END FOOTER -->
                        </td>
                    </tr>
                </table>
                <!-- // END TEMPLATE -->
            </td>
        </tr>
    </table>
</center>
</body>
</html>

我正在返回未扩展的索引模板... enter image description here

0 个答案:

没有答案