Laravel 4: if statement in blade layout works weird

Can someone explain to me why I get a blank screen with the printed line "@extends (" layouts.default ")" if I request a page normally (not ajax)?

@if(!Request::ajax())
  @extends('layouts.default') 
  @section('content')
@endif
Test
@if(!Request::ajax())
  @stop
@endif

I am trying to solve the problem with Ajax, I do not want to create 2 templates for each type of request, and I also want to use blade templates, so using controller layouts does not work for me. How can I do this in a blade template? I looked at this Laravel: how to display only one section of a template?

By the way. If I request it using ajax, it works as it should.

+5
source share
3 answers

Yes @extends should be on line 1.

PJAX. , , . , , . - PJAX , :

protected $layout = 'layouts.default';

public function index()
{
  if(Request::header('X-PJAX'))
  {
    return $view = View::make('home.index')
      ->with('title',  'index');
  }
  else
  {
    $this->layout->title = 'index';
    $this->layout->content = View::make('home.index');
  }
}
+9

@extends 1, , .

ajax, , , .

:

if ( Request::ajax() )
{
    return Response::eloquent($books);  
} else {
    return View::make('book.index')->with('books', $books);
}

: http://forums.laravel.io/viewtopic.php?id=2508

+3

@extends((Request::ajax())?"layout1":"layout2")
+3

All Articles