Laravel 4 Blade Templating Engine with Conditional layout

三世轮回 提交于 2019-12-05 06:28:11

问题


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

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

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

Thanks


回答1:


Try on the first line:

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

EDIT

You also can use it this way:

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


来源:https://stackoverflow.com/questions/17455373/laravel-4-blade-templating-engine-with-conditional-layout

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