rcrowe / TwigBridge

Give the power of Twig to Laravel
MIT License
895 stars 166 forks source link

Any idea why I would need to use file extension '.php' vs. '.twig' ? #161

Open SteamboatColorado opened 9 years ago

SteamboatColorado commented 9 years ago

I would like to use the extension .twig, but stuck in .php for file names.

I can do this: {% extends 'users.base' %} (where users.base is really app/views/users/base.php) but not {% extends 'users.base.twig' %}

It would be nice to keep my twig files with the extension like base.twig, user_photos.twig, etc.

Is that an easy config change? Thank you!

SteamboatColorado commented 9 years ago

I am guessing that Laravel just uses it's own dot (.) notation, so maybe .php may indicate a sub directory. However, maybe someone knows if there is a setting where file extensions could be used with .twig? Thank you!

meetraz commented 9 years ago

FWIW, the twig extensions are working for me.

simon-lifelike commented 9 years ago

but not {% extends 'users.base.twig' %}

you should leave out the file extension. {% extends 'users.base' %} will work when the file name is app/views/users/base.twig

j3rrey commented 7 years ago

Hey guys, I have a somewhat similar problem. The extends function just does not work, I tried every possible way to extend my base template

StackOverflow: http://stackoverflow.com/questions/42090602/laravel-5-3-rcrowe-twigbridge-0-9-4

Laravel 5.3.* Twigbridge ^0.9.4 OSX

My Folder Structure: views/templates/email/files.twig I even tried putting everything in views/

My test Route:

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

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

This does not work:

{%  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 %}

Nor this:

{%  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 %}

nor this:

{%  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 %}

nor this, which is suggested by autocompletion:

{%  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 %}

my index:

{% 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>

Any hints or recommendations?