具有条件布局的Laravel 4 Blade模板引擎 [英] Laravel 4 Blade Templating Engine with Conditional layout

查看:51
本文介绍了具有条件布局的Laravel 4 Blade模板引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Blade的L4.我希望能够有条件地扩展布局.对于正常使用,我想扩展主版面,对于ajax渲染,我希望能够扩展ajax模板.我使用以下代码:

I'm using L4 with Blade. I'd like to be able to conditionally extend a layout. For normal use, I'd like to extend the master layout, and for ajax renders, I'd like to be able to extend the ajax template. I use the following code:

@if ( isset($ajax) )
    @extends('layouts.ajax')
@else
    @extends('layouts.master')
@endif

但是,当页面呈现时,它只会打印出@extend('layouts.master').

But when the page renders it just prints out @extend('layouts.master').

有人知道如何有条件地扩展布局吗?

Does anyone know how to conditionally extend a layout or another?

谢谢

推荐答案

尝试在第一行:

@extends('layouts.' . isset($ajax) ? 'ajax' : 'master')

编辑

您也可以通过以下方式使用它:

You also can use it this way:

@extends(((Request::ajax()) ? 'layouts.ajax' : 'layouts.master'))

这篇关于具有条件布局的Laravel 4 Blade模板引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆