问题
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