flashz's avatar

Blade template just not working

I copied it exactly from Laravel documentation. My child.blade.php:

@extends('layouts.application')

@section('title', 'Page Title')

@section('sidebar')
    

    <p>This is appended to the master sidebar.</p>
@endsection

@section('content')
    <p>This is my body content.</p>
@endsection

My application.blade.php:

<html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('content')
        </div>
    </body>
</html>

In web:

Route::get('blade', function () {
    return view('child');
});

However, when I visit the URL it just shows me: @extends('layouts.application') in plain HTML text?!

https://gyazo.com/2938c6bd3dc19ebeabaacb680ae4b234

0 likes
22 replies
Snapey's avatar

Is your application.blade.php file inside the layouts folder?

ejdelmonico's avatar

I see you have two layouts, make sure you are using the correct one. Also, you @include('sidebar') in application.blade.php.

flashz's avatar

I have two layouts, app.blade.php is the old one. I made application.blade.php to test why it's not working (using documentation example, but still the same problem).

@extends('layouts.application')

I tried removing everything related to the sidebar, still the same result. GIF: https://gyazo.com/28027a265d6ca552836f9eebe67daf6a

ejdelmonico's avatar

Remove the sidebar section from the child.blade.php file and the layout and try again. I think its failing after extending the layout.

Snapey's avatar

php artisan view:clear never hurts

2 likes
ejdelmonico's avatar

Also, make sure that when you refresh the browser, you have the dev tools open and cache disabled checked.

Snapey's avatar

This might sound odd, but using your browser tools, inspect the network traffic when you refresh the page.

In the response that comes from the server, is @ the very first character received?

flashz's avatar

Just tried it with Google Chrome, still the same result. Cache disabled, network response first character is '@':

https://gyazo.com/424d7d297454925c8e0f1ef2889e22ab

Maybe it really is related to PHP somehow.. I once had it working with virtualbox, now using php artisan serve it's not working.

ejdelmonico's avatar

@snapey must have the answer for you because he knew about it. Other than that, Valet is awesome. I use both Valet and Homestead depending on the project and I like the convenience. I personally, never used the artisan serve server.

flashz's avatar

I wish I could use Valet but I'm not on a mac. I used 'php artisan serve' because compared to Homestead (when I used it last time), it is much simpler.

ejdelmonico's avatar

True, it is simple but you lose the flexibility of Homestead. Homestead is a pain to setup on Windows but it does have a lot of advantages. There is plenty of discussion on solving Windows specific issues with Homestead install. But, Homestead has far less issues than using WAMP or XAMP.

flashz's avatar

I understand but it should work with my solution aswell..

ejdelmonico's avatar

I agree that it should work. It could be a strange issue with Sublime. Try deleting the @extends line and re-typing it in...don't copy and paste to see if it matters. I have had issues with Sublime before and that usually fixes the problem.

flashz's avatar

Unfortunately that is not the problem :(

ZetecVan's avatar

I had this happen with me, and after hours of trying I couldn't it out, so created a new project (laravel new project) and put the code in there and everything worked ok. As @ejdelmonico says, it may be a bad install.

Please or to participate in this conversation.