laravel 模板 blade

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   io   strong   檔案   

控制器布局

在Laravel架構中使用模板的一種方法就是通過控制器布局。通過在控制器中指定 layout 屬性,對應的視圖會被建立並且作為請求的預設返回資料。

在控制器中定義一個布局

class UserController extends BaseController {    /**     * The layout that should be used for responses.     */    protected $layout = ‘layouts.master‘;    /**     * Show the user profile.     */    public function showProfile()    {        $this->layout->content = View::make(‘user.profile‘);    }}
Blade模板

Blade是Laravel架構下的一種簡單又強大的模板引擎。 不同於控制器布局,Blade模板引擎由模板繼承和模板片段驅動。所有的Blade模板檔案必須使用Blade .blade.php 副檔名。

定義一個Blade布局

<!-- Stored in app/views/layouts/master.blade.php --><html>    <body>        @section(‘sidebar‘)            This is the master sidebar.        @show        <div class="container">            @yield(‘content‘)        </div>    </body></html>

使用一個Blade布局 (檔案名稱.blade.php)

@extends(‘layouts.master‘)@section(‘sidebar‘)    @parent    <p>This is appended to the master sidebar.</p>@stop@section(‘content‘)    <p>This is my body content.</p>@stop

(渲染時直接接檔案名稱,不要blade)

注意一個Blade布局的擴充視圖簡單地在布局中替換了模板片段。通過在模板片段中使用 @parent 指令,布局的內容可以被包含在一個子視圖中,這樣你就可以在布局片段中添加諸如側邊欄、底部資訊的內容。

Sometimes, such as when you are not sure if a section has been defined, you may wish to pass a default value to the@yield directive. You may pass the default value as the second argument:

@yield(‘section‘, ‘Default Content‘);
更多:
http://v4.golaravel.com/docs/4.1/templates#controller-layouts

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.