Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel / Blade: tabs/spaces not included properly

The issue:

Tabs are not being processed properly when including templates using Blade (in a Laravel app) after viewing the page source code in the browser

default.blade.php:

<html>
    <head>
        @include('includes.head')
    </head>

    <body>
    </body>
</html>

head.blade.php:

<meta charset="utf-8">
<meta name="description" content="">
<meta name="Test" content="">

What it looks like when viewing source on the browser:

<html>
    <head>
        <meta charset="utf-8">
<meta name="description" content="">
<meta name="Test" content="">
    </head>

    <body>
    </body>
</html>

As you can see, the last two meta tags are for some reason being tabbed backwards instead of aligning with the first meta tag. What's going on?

like image 989
Aran Bins Avatar asked Oct 28 '25 10:10

Aran Bins


2 Answers

Just adding @Andrei Lupuleasa answer, blade consider indentation from your master layout. so it is taking indentation from master.blade.php. please put 2 tab space in your head.blade.php.

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
like image 164
Dev Ramesh Avatar answered Oct 31 '25 02:10

Dev Ramesh


Put tabs in your head.blade.php.

     <meta charset="utf-8">
     <meta name="description" content="">
     <meta name="Test" content="">

First line is indented ok because it uses the indentation from default.blade.php, the tabs before @include...

From what I see there is also a problem with blade indentation: https://laracasts.com/discuss/channels/laravel/problem-with-indentation-in-blade-views

So i suggest to remove the indentation from layout:

<html>
    <head>
@include('includes.head')
    </head>

    <body>
    </body>
</html>

It is not pretty but it will solve your problem.

like image 28
Andrei Lupuleasa Avatar answered Oct 31 '25 02:10

Andrei Lupuleasa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!