Support the ongoing development of Laravel.io →
Views Blade
Last updated 2 months ago.
0

Up up up

Last updated 2 months ago.
0

AnasT said:

Did you try the @section @show instead of @yield? http://laravel.com/docs/templates#blade-templating

Yes. Same thing

Last updated 2 months ago.
0

I've opened a bug on github but Taylor said to write here, so I suppose he thinks I'm doing something wrong... but what? :)

Last updated 2 months ago.
0

Someone gave me this link

This does not solve the problem but write down the cause.

I think it's a very bad view handling. Are we sure we can't change it?

Last updated 2 months ago.
0

Hum try this @include ('partial', ['foo' => ''])

Last updated 2 months ago.
0

AnasT said:

Hum try this @include ('partial', ['foo' => ''])

This can solve the undefined error, but I would find a solution that does not force me to execute all the application logic for a view that will not be shown.

If have a view composer for the partial view, it will be executed either way.

Last updated 2 months ago.
0

up up up

Last updated 2 months ago.
0

In this example, you only want the partial if foo is defined? In partial.blade.php you might:

@if ( isset( $foo ) )
    Hello {{ $foo }}
@endif

Is it possible to do this in layout.blade.php?

@if ( isset( $foo ) )
   @include( 'partial' );
@endif
Last updated 2 months ago.
0

This does not work if you use a view composer for the partial template. It is not a solution in any case, cause if I have 10 includes in my overridden layout section I have to check every var I pass to that view and I could completely go nuts. I hope you agree with me...
Laravel should be smart enough to block the render of the overridden views in my opinion.

Last updated 2 months ago.
0

What do you prefer to happen if $foo is not defined? Some might want those errors/exceptions to see what they overlooked.

Last updated 2 months ago.
0
Hello {{{ $foo or 'Default' }}}
Last updated 2 months ago.
0

I think you guys are fighting against the wrong monster... :D
The point here is that laravel loads and compiles all the thousands of partial views eventually included in the layout content section even if in the custom view I override the same section with 0 view.
Both of you are suggesting me to check for the existence of the variables in those partials. I can surely do that removing the error but laravel continue to load thousands of useless views.
Also, if I have view composers/creators binded to my partial views they will be executed causing a pointless performance degradation.
Is it a problem just for me?

Last updated 2 months ago.
0

You are right, I don't understand why you are trying to extend 'layout' instead of 'base' from your 'custom' while you're not using the partial (eventually 100 partials).

Last updated 2 months ago.
0

my views are a just a little bit more complicated than this gist. I have a structure of DRY views and in this scenario I need to extend layout not base

Last updated 2 months ago.
0

How can Laravel know whether variables in partials are defined without opening them?

Last updated 2 months ago.
0

Don't know how the Blade compiler has been coded, but in theory I think it has to be possible to study an architecture that builds the whole template first (expanding all blade placeholders like @extends, @section, @include) and then compile all vars used in that final template. isn't it?

Last updated 2 months ago.
0

I'm coming up against the same issue now.

Here's my use case, for illustration.

I have a base blade template used for a category of posts. For most categories of posts this logic is fast, and is used as is. But for one particular category of posts it is incredibly slow, because the posts in this category are a lot more numerous and complicated, simply due to the nature of the data. For that reason among others, I have another version of the view for this particular category, which just overrides that particular section with something much faster (a simpler way of displaying the data, with fewer details and therefore calculations). However, both versions of the section are evaluating, even though only the override is eventually shown.

It seems to me that this is a bug or large oversight in the blade templating system.

Did you ever come up with a solution?

Last updated 6 years ago.
0

Stumbled with the same issue here. Not sure if most people understood it properly, though.

I have a master view that has a @section which contains an @include to a navbar view.

The included navbar has an Auth::guest().

I create a view that extends the master view and overrides the navbar section (without calling @ parent).

Expected result: Auth::guest() is not executed. This is because the default content of the navbar section is overriden

Actual result: Auth::guest() is executed.

Last updated 6 years ago.
0

pupi1985 said:

Stumbled with the same issue here. Not sure if most people understood it properly, though.

I have a master view that has a @section which contains an @include to a navbar view.

The included navbar has an Auth::guest().

I create a view that extends the master view and overrides the navbar section (without calling @ parent).

Expected result: Auth::guest() is not executed. This is because the default content of the navbar section is overriden

Actual result: Auth::guest() is executed.

Exactly the same problem. Any solution?

0

This should be renamed to "Why, after so many years and countless versions Blade still sucks" Even as simple as something like this is failing:

// resources/views/layouts/app.blade.php

@section('header')
    I am default header
@show

@yield('content')

@section('footer')
    I am default footer
@show
// resources/views/view.blade.php

@extends('layouts.app')

@section('header')
    Overridden header
@stop

@section('content')
    I am content
@endsection

@section('footer')
@endsection

If you would think that this would not load default header section - you would be wrong (also tried it with @overwrite). What is the point of overriding the content if it still gets loaded?

0

Hi, any news on this?

0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

spescina spescina spescina Joined 14 Feb 2014

Moderators

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

Your logo here?

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

© 2022 Laravel.io - All rights reserved.