I'm using blade templating
with laravel 4.2
I have a little issue with the @yield
function which works with the @section
function.
Let's say in my layout template layout.blade.php
I have the following statement:
<meta name="description" content="@yield('description')">
and in contact.blade.php
which extends layout.blade.php
I have this:
@section('description')
this is the contact page
@stop
The output is this:
<meta name="description" content="this is the contact page
">
The problem is the line break
added automatically at the end the section rendering.
Do you have an idea how to avoid this unwanted behaviour?
Laravel Blade template engine enables the developer to produce HTML based sleek designs and themes. All views in Laravel are usually built in the blade template. Blade engine is fast in rendering views because it caches the view until they are modified. All the files in resources/views have the extension .
You can try: {!! 'first line <br> second line' !!}
The main advantage of using the blade template is that we can create the master template, which can be extended by other files.
Two of the primary benefits of using Blade are template inheritance and sections. We can define a blade page as a combination of layout and sections. Since most of the general web applications will have the same layout across the web pages.
You can use {{trim(View::yieldContent('description'))}}
I had the same problem. I had a few modal windows on the page, that had a common layout but different bodies, titles and "id" attributes. So, "id" attribute should be yielded without any spaces around.
The @yield
statement compiles to echo $__env->yieldContent
call (BladeCompiler.php, compileYield method). $_env
here is an instance of \Illuminate\View\Factory
. So you can use {{trim(View::yieldContent('description'))}}
where View is a facade.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With