Laravel刀片模板部分重复/缓存错误 [英] Laravel Blade Templates Section Repeated / cache error
问题描述
我正在寻找Bootstrap网站,因此,已将常见的twitter bootstrap组件放入刀片模板中.
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>
这样,每次我希望使用面板时,都可以使用@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
我面临的问题是,而不是显示panel1.blade.php
的内容,而是重复了sidebar.blade.php
中声明的panel2.blade.php
的内容panel1.blade.php
的内容(显示两次).>
Blade是否正在缓存请求,这就是为什么将panel1重复两次的原因?有没有一种方法可以替代此行为,或者我是否以从未想到的方式使用刀片模板引擎?
您可以通过覆盖这些部分.尝试使用已有的内容,但是要使用以下两个更新的子视图:
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
它已经在这里经过测试和运行,尽管我不确定它是否是@overwrite
的预期用途,所以请进行彻底测试!
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?
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!
这篇关于Laravel刀片模板部分重复/缓存错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!