Reputation: 763
I was wondering if it is possible to nest templates inside of templates in Laravel 4. I would like to have a master wrapper template that would include things like the doctype, header and footer and then be able to load in templates into the master templates body section.
This would give me the flexibility of having a nested template for my application pages without having to duplicate code while giving me the ability to use the master template for non-application pages.
Can someone please provide an example as to how this would be done using blades templating engine? Is it possible to pass in a value from the router and then have that value be pushed down to your nested template?
EDIT:
Here is my code for index.blade.php
@extends('layouts.master')
@section('title')
Some page
@endsection
@section('content')
@include('layouts.app')
@endsection
Upvotes: 0
Views: 3752
Reputation: 3668
You can try this for multiple level nesting
//index.blade.php
@extends('layouts.master')
@section('title')
@parent
:: new title
@stop
@section('content')
<p>some static contents here</p>
@stop
//app.blade.php
@section('content')
@parent
<p>Add here what ever you want to add</p>
@stop
now either from your Route or Controller you can nest the index and app, ex-
return View::make('index')->nest('content','layouts.app');
And in case you want to pass data to child view you can do this by passing the data as third parameter to nest()
return View::make('index')->nest('content','layouts.app',$data);
Upvotes: 2