Laravel: View and Subviews

Asked

Viewed 1,433 times

3

Someone knows how mine layouts.default can load multiple views whenever they are called. For example I want to call views from menus and the file menu.blade.php has to receive data too.

2 answers

3

Another way would be to create the View and move on to the leading 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));

Upshot

inserir a descrição da imagem aqui

Result in Hmtl

<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>

2


I usually use the method View::share("variável", "valor"); to share variables across 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 ...;

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.