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.
我一直在寻找有关如何在laravel 4中构建漂亮布局的信息或教程,我真的找不到多少。大多数人似乎只是说“它从3改变了很多”。这很棒....有人可以在L4中发布信息或者是关于模板的教程吗?具体来说,知道如何创建统一设计,或者在不必使用Blade引擎的情况下引入其他模板,这将是一件好事。
I found some details on changes here: https://github.com/jasonlewis/jasonlewis.me/blob/master/articles/laravel-4-illuminating-your-laravel-3-applications.md
我在这里找到了一些有关变化的细节: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.
但是,作者提到像“render_each()”这样的东西已被删除,但没有提到要使用的内容。
Ideally, I'd like to have a single design template, which pulls in smaller sub-layouts for various pieces of the design.
理想情况下,我希望有一个单独的设计模板,它可以为各种设计提供更小的子布局。
Thanks!
谢谢!
1 个解决方案
#1
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.
您仍然可以使用Blade模板引擎执行此操作。此外,Laravel 4的Composer集成的一个好处是,您可以轻松地放入任何您想要的模板系统,例如Twig。 Blade虽然内置,但定义模板和继承非常容易。
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
如Laravel 4 Blade文档中所述,您可以为整个控制器(或BaseController类中的所有控制器)指定模板,
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):
然后在你的控制器方法中,你可以添加以下内容,它将继承你指定的$ layout(不需要显式返回任何东西):
$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')
.
您仍然可以@yield('things'),定义@section('like_a_sidebar'),并使用@extends('layouts.another_layout')。
#1
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.
您仍然可以使用Blade模板引擎执行此操作。此外,Laravel 4的Composer集成的一个好处是,您可以轻松地放入任何您想要的模板系统,例如Twig。 Blade虽然内置,但定义模板和继承非常容易。
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
如Laravel 4 Blade文档中所述,您可以为整个控制器(或BaseController类中的所有控制器)指定模板,
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):
然后在你的控制器方法中,你可以添加以下内容,它将继承你指定的$ layout(不需要显式返回任何东西):
$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')
.
您仍然可以@yield('things'),定义@section('like_a_sidebar'),并使用@extends('layouts.another_layout')。