简体   繁体   English

Laravel嵌套子视图

[英]Laravel nesting child views

All of us know that Laravel allows us to nest child view easily: 我们所有人都知道Laravel允许我们轻松嵌套子视图:

return View::make("myView")->nest("sidebar", "sidebar");

But what if I need the sidebar in my every view. 但是如果我在每个视图中都需要侧边栏怎么办。 That seems awkward to nest it each time. 每次嵌套它似乎很尴尬。 specially that there are many nested views such as : footer, header, navigation, sidebar. 特别是有许多嵌套视图,例如:页脚,页眉,导航,边栏。

Is there a way to have a nested view without explicitly declaring it each time? 有没有一种嵌套视图而无需每次都明确声明的方法?

I don't want to use Blade Engine . 我不想使用Blade Engine

I believe you can attach a view composer to the layout specified in your BaseController . 我相信您可以将View BaseController附加到BaseController指定的布局。

Something like: 就像是:

View::composer('layout', function($view)
{
    $view->with('sidebar', 'sidebar');
});

You can put this code on routes.php or create a composers.php in app folder. 您可以将此代码放在route.php上,或在app文件夹中创建composers.php。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM