6

I have a blade template master.blade that has the following code:

<title>@yield('meta-title')</title>

And then in any views that extend this template, the data can be passed in like this:

@section('meta-title')My Meta Title @stop

However, this ALWAYS adds a space at the end. If I remove the space in the code so it looks like the following, then it will not recognise the @stop and the page breaks:

@section('meta-title')My Meta Title@stop

Is there a way to achieve this functionality (dynamically inject content into the header without any spacing before or after) either using @yield or some other way?

Blade Template Docs

0

1 Answer 1

8

Pass a second parameter to @section, like so: @section('meta-title', 'My Meta Title'), no need for @stop

It is indeed in the docs: http://laravel.com/docs/5.1/blade#template-inheritance

2
  • 1
    Oh my god! I have read those docs 1000 times and never saw that! Thank you. Commented Oct 26, 2015 at 15:48
  • 1
    How do I solve this issue when I need to @overwrite the @section? Commented Dec 14, 2016 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.