2013-04-06 83 views
0

我有這樣的模板。如何根據不同的請求更改內容區域?

<div class="content"> 
     @yield('content') //this area should load different files on different URI's 
</div> 

如果我加載.com/register,它應該在的@yield.的地方加載register.blade.php如果我打開別的東西,它會加載這一觀點。

我將定義哪些文件應該在Routes.php裝載Route::get();

完整的源在這裏,可讀性更強:http://pastebin.com/t2Md20r9所以你可以看到我做了什麼至今。

應該做什麼?

回答

2

你很近,就在register.blade.php擴展您的佈局。

1.Put您的模板文件中views/layouts/master.blade.php

2.In您register.blade.php把

@layout('layouts.master') 

在Laravel 4

@extend('layouts.master') 

之上。

3.Now使用return View::make('register');

+0

什麼是高手? – Aristona 2013-04-06 19:36:09

+0

它是你的模板/佈局文件名,你可以隨心所欲地命名它。但正如我在第一步告訴master.blade.php :) – Usman 2013-04-06 19:53:55

0

您可以通過它在你的Route.php文件是這樣的:

Route::get('your_page', function() { 
    View::make('your_page')->with('contentTemplate', 'register'); 
} 

Route::get('other_page', function() { 
    View::make('other_page')->with('contentTemplate', 'other_content'); 
} 

而且在your_page,做

<div class="content"> 
    @render($contentTemplate) 
</div> 
相關問題