2013-01-02 128 views
1

我無法弄清楚如何將幾個視圖合併到一個沒有刀片的部分。Laravel模板嵌套視圖

電腦板:

public $layout = 'layouts.template'; 
action_index{ 
    $this->layout->nest('content', 'view1'); 
    $this->layout->nest('content', 'view2'); 
} 

的template.php:

<?php echo Section::yield('content'); ?>

view1.php:

<?php Section::start('content');?> 
div1.... 
<?php Section::stop(); ?> 

view2.php:

<?php Section::start('content');?> 
div2.... 
<?php Section::stop(); ?> 

現在 - 它只顯示視圖2

如何才達到類似的東西:

$content = View::make('view1'); 
$content = View::append('view2'); // append view2 to view1? 
$this->layout->with('content', $content); 
+0

我知道你沒有使用刀片,但考慮使用它。這裏的嵌套很容易。 –

回答

2
$content = View::make('view1') . View::make('view2'); 

這應該工作。在View類中有一個__toString魔術方法,所以當它碰到字符串連接運算符時,它會呈現爲一個字符串。 $ content將是一個包含來自兩個呈現視圖的HTML的字符串。