本文介绍了有条件地在Blade中扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以使用Blade模板语言来执行条件@extends语句?

Is there any way to do a conditional @extends statement in the Blade templating language?

@if(!Request::ajax())
    @extends('dashboard.master')
    @section('content')
@endif

<div class="jumbotron">
    Hey!
</div>

@if(!Request::ajax())
    @stop
@endif

输出

当请求不是AJAX时,它会打印出@extends('dashboard.master'),但是AJAX请求可以正常工作.

Output

When the request was not AJAX it printed out @extends('dashboard.master'), but the AJAX request worked fine.

停止包含用于AJAX的主模板(包括headerfooter),以便可以轻松显示所请求的内容

Stop including the master template (which includes header and footer) for AJAX so it can easily display the requested content

推荐答案

在主布局中:

   @if(!Request::ajax())

       //the master layout with @yield('content'). i.e. your current layout

   @else

       @yield('content')

   @endif

这篇关于有条件地在Blade中扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:00