Laravel Blade Templates Section Repeated / cache error

亡梦爱人 提交于 2019-12-08 19:42:15

问题


I am looking to Bootstrap my site and as such, have put common twitter bootstrap components into blade templates.

sidebar.blade.php

@include('panel1')
@include('panel2')

panelTemplate.blade.php

<div class="panel panel-primary">   
    <div class="panel-heading">
        <div class="panel-title">
            @yield('title')
        </div>
    </div>
    <div class="panel-body">
            @yield('body')
    </div>
    <div class="panel-footer">
            @yield('footer')
    </div>
</div>

This way, every time I wish to use a panel, then I can use @extends('panelTemplate').

panel1.blade.php

@extends('panelTemplate')
@section('title')
 title panel 1
@stop

@section('body')
 body panel 1
@stop

@section('footer')
 footer panel 1
@stop

panel2.blade.php

@extends('panelTemplate')
@section('title')
 title panel 2
@stop

@section('body')
 body panel 2
@stop

@section('footer')
 footer panel 2
@stop

The problem that I am facing is that instead of showing the contents of panel1.blade.php, then the contents of panel2.blade.php as declared in sidebar.blade.php the contents of panel1.blade.php is being repeated (shown twice).

Is Blade caching the request which is why panel1 is being repeated twice? Is there a way to override this behaviour or am I using the blade templating engine in a way which it was never intended?


回答1:


You can achieve this by overwriting the sections.. try what you have already, but with these two updated sub-views:

panel1.blade.php

@extends('panelTemplate')

@section('title')
 title panel 1
@overwrite

@section('body')
 body panel 1
@overwrite

@section('footer')
 footer panel 1
@overwrite

panel2.blade.php

@extends('panelTemplate')

@section('title')
 title panel 2
@overwrite

@section('body')
 body panel 2
@overwrite

@section('footer')
 footer panel 2
@overwrite

It's tested and working here, though I'm not sure it's the intended use of @overwrite, so test thoroughly!



来源:https://stackoverflow.com/questions/18659615/laravel-blade-templates-section-repeated-cache-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!