Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p> You are mixing two different layout approaches of Laravel. This way you are rendering the layout view, include the home view and try to include inside again the layout.</p> <p>My personal preference is the controller approach.</p> <h2>Controller Layouts</h2> <p>The controller and the layouts can remain the same.</p> <p><em>Note: As a shortcut you could nest the content instead of View::make, that automaically renders it when you echo it out in the layout.</em></p> <p>In home.blade.php remove the @layout function.</p> <p><strong>Edit (example):</strong></p> <p><em>controllers/home.php</em></p> <pre class="lang-php prettyprint-override"><code>&lt;?php class Home_Controller extends Base_Controller { public $layout = 'layouts.default'; public function action_index() { $this-&gt;layout-&gt;title = 'title'; $this-&gt;layout-&gt;nest('content', 'home', array( 'data' =&gt; $some_data )); } } </code></pre> <p><em>views/layouts/default.blade.php</em> </p> <pre class="lang-php prettyprint-override"><code>&lt;html&gt; &lt;title&gt;{{ $title }}&lt;/title&gt; &lt;body&gt; {{ $content }} &lt;/body&gt; &lt;/html&gt; </code></pre> <p><em>views/home.blade.php</em></p> <p>Partials are included in the content. </p> <pre class="lang-php prettyprint-override"><code>@include('partials.header') {{ $data }} @include('partials.footer') </code></pre> <h2>Blade Layouts</h2> <p>If you want this approach you have a few problems there. First, you are including new content after the layout. Not sure if intentional, but the <em>@layout</em> function itself is basicly just an <em>@include</em> restricted to be at the very beginning of the view. So if your layout is a closed html, any include after that will be appended after your html layout.</p> <p>Your content should use sections here with the <em>@section</em> function and <em>@yield</em> it in your layout. The header and footer could be included in the layout with <em>@include</em> or if you want to define it in the content view then put those in a <em>@section</em> too, like below. If you define it that way if a section doesn't exist nothing gets yielded.</p> <p><em>controllers/home.php</em></p> <pre class="lang-php prettyprint-override"><code>&lt;?php class Home_Controller extends Base_Controller { public function action_index() { return View::make('home')-&gt;with('title', 'title'); } } </code></pre> <p><em>views/layouts/default.blade.php</em> </p> <pre class="lang-php prettyprint-override"><code>&lt;html&gt; &lt;title&gt;{{$title}}&lt;/title&gt; &lt;body&gt; @yield('header') @yield('content') @yield('footer') &lt;/body&gt; &lt;/html&gt; </code></pre> <p><em>views/home.blade.php</em> </p> <pre class="lang-php prettyprint-override"><code>@layout('layouts.default') @section('header') header here or @include it @endsection @section('footer') footer @endsection @section('content') content @endsection </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload