0

I've been looking for information or tutorials regarding how to construct nice layouts in laravel 4 and I really can't find much. Mostly people just seem to say "it changed a lot from 3". That's great.... could someone post info or maybe a tutorial on templating in L4? Specifically, it'd be nice to know how to create a unified design, or pull in other templates without necessarily having to use the Blade engine.

I found some details on changes here: https://github.com/jasonlewis/jasonlewis.me/blob/master/articles/laravel-4-illuminating-your-laravel-3-applications.md

however, the author mentions that things like "render_each()" have been removed, but doesn't mention what to use instead.

Ideally, I'd like to have a single design template, which pulls in smaller sub-layouts for various pieces of the design.

Thanks!

warkior
  • 93
  • 9

1 Answers1

1

You can still do this with the Blade template engine. Additionally, one of the nice things about Laravel 4's Composer integration is that it's very easy for you to drop in any template system you want, such as Twig. Blade is built in though, and defining templates and inheritance is very easy.

As detailed in the Laravel 4 Blade documentation, you can specify a template for an entire controller (or all of your controllers from the BaseController class) with

protected $layout = 'layouts_folder.master_layout_name';

Then in your controller methods, you can just add the following, which will inherit from the $layout you specified (no need to explicitly return anything):

$this->layout->content = View::make('layout_folder.layout_name');

You can still @yield('things'), define a @section('like_a_sidebar'), and use @extends('layouts.another_layout').

BenjaminRH
  • 11,974
  • 7
  • 49
  • 76
  • I guess for me the problem I keep running into is how to get the `@section` into the `@yield`. I have each but I don't understand connecting them and the documentation doesn't explain this. – kkirsche Jun 05 '13 at 20:47
  • 1
    @kkirsche, and anyone else who happens by, this post shows an example of the [code]@section[/code] tag and how to display them in the layout - http://stackoverflow.com/questions/12524712/templating-in-laravel – Terre Porter Aug 22 '13 at 16:33