Laravel: View and SubViews

3

Does anyone know how my layouts.default can load multiple views every time they are called. For example I want to call the views of the menus and the menu.blade.php file has to receive data as well.

    
asked by anonymous 28.06.2014 / 06:01

2 answers

2

I use the View::share("variável", "valor"); method to share variables between all views ... but I believe there should be better methods ...

ex.:

//No controller
public function minhaAction(){
   View::share("menu", array(...)); //a variavel $menu estara disponivel em todas as views...
   return ...;

}
    
28.06.2014 / 06:15
3

Another way would be to create View and move to main as?

menu.blade.php

<h1>{{$model['Titulo']}}</h1>

view.blade.php

<html>
<head>
    <title>View Principal</title>
</head>
<body>
    {{$model['cabeca']}}
    {{$model['menu']}}
    {{$model['rodape']}}    
</body>
</html>

método de carregamento

$cabeca = View::make("menu")->with('model', array('Titulo' => 'Cabeça do Site'));
$menu   = View::make("menu")->with('model', array('Titulo' => 'Menu do Site'));
$rodape = View::make("menu")->with('model', array('Titulo' => 'Rodapé do Site'));

return View::make("view")->with('model', array('cabeca' => $cabeca,
                                               'menu' => $menu,
                                               'rodape' => $rodape));

Result

Hmtl result

<html>
<head>
    <title>View Principal</title>
</head>
<body>
    <h1>Cabeça do Site</h1> 
    <h1>Menu do Site</h1>   
    <h1>Rodapé do Site</h1>
</body>
</html>
    
28.06.2014 / 15:42