2

I have an annoying bug with Laravel producing whitespace characters into my source code when I use @extends and @yield.

For example, these are the first lines of my index.blade.php file:

@extends('template.main')

@section('metas')
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
@stop

And my template file starts like this :

<!DOCTYPE html>
<html lang="{{ Config::get('app.locale') }}">
    <head>
        @yield('metas')

And this is the output I get :

      <!DOCTYPE html>
<html lang="fr">
    <head>
         <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

As you can see, there are six whitespace characters at the very start of the file (before the DOCTYPE declaration), and one before the first meta element.

This is not something big but I'd like to find a way to fix it. I tried everything from using spaces, tabs, eliminating blank lines... but nothing has worked so far!

Spooky
  • 2,966
  • 8
  • 27
  • 41
  • 1
    You must `echo`ing that whitespace, check your controllers, routes file etc. On the 4.0.8 version I'm running that doesn't happens. – afarazit Oct 26 '13 at 22:44

1 Answers1

1

You surelly have them (the spaces) before the calling the blade functions. I'll explin that:

Before @extends('template.main), probably in a line above, you have this 6 spaces. Same apply to the @sections('metas') which probably has a space in the final, before you 'broke' the line.

I bet that this is the problem. I hope it helps! :D

Dennis Braga
  • 1,448
  • 3
  • 20
  • 40
  • There is no whitespaces before my blade ... It seems to be related to my DB calls, I know, it's crazy. If I delete some DB calls, the number of whitespaces go down. This is the closest I can reach to this problem :( – Jason Lemay Nov 19 '13 at 02:11
  • In that case, we had to see you query's and see if any of them is printing "ghost white spaces" – Dennis Braga Nov 20 '13 at 18:56