Support the ongoing development of Laravel.io →
posted 10 years ago
Views Blade

Hello,

I'm facing a problem with blade templating and my layouts.

Here's my layout (in app/views/layouts/test.php:

<div id="@yield('div-id')">
  <p>@yield('content')</p>
</div>

Here's my view:

@extends('layouts.test')

@section('div-id')
  test_id
@stop

@section('content')
  @lang('texts.test')
@stop

And here's the result:

<div id=" test_id ">
  <p> test </p>
</div>

As you can see, there are white spaces before and after each yielded text. It is causing issues as you can imagine (css and js related).

Is there any way to tell blade not to add those useless (to me, maybe they have a purpose) white spaces?

Thank you

Last updated 3 years ago.
0

I know this issue too. Try not to intend your section content and remove white-space at line endings.

@section('div-id')
test_id
@stop

@section('content')
@lang('texts.test')
@stop
Last updated 3 years ago.
0

Thank you for you quick answer, it works for the first white-space (not always though), but not for the second. I checked and I have no white-spaces or tabs at the end of my lines. If I remove the CR LF, it's not working at all (it appears there need to be a line break before the @stop command).

Result with your input is:

<div id="test_id ">
  <p> test </p>
</div>

I don't know why it doesn't fix the first white-space of the 'content' section tho.

Last updated 3 years ago.
0

Another solution: totally forgot about this ^^

@section('title', 'value')

Result

<title>value</title>

Example: http://alexwenzel.de/2014/223/line-breaks-in-blade-sections-and-yields

Last updated 3 years ago.
0

Ow, that's great to know, thank you!

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

SynRJ synrj Joined 3 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.