如何在Laravel框架中导入其他部分的部分?

时间:2018-01-30 16:52:43

标签: php laravel laravel-blade

我想在其他部分中导入部分模板。 例如,我已经使用了标题部分。

目前的结构是

-- header.blade.php
--+ partials
  |__ nave.blade.php

在这种情况下,我想在标题部分中使用nav partial。

但是我无法添加导航到标题。我可以看到找不到错误。

有什么特殊方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

Assuming you have a main.blade.php page. The content is like this:

@include('layouts.header')
<section> Main Content {{$slot}} </section>
@include('layouts.footer')

In header.blade.php, here is your content:

<div class="container">
  <div id="app">  
@include('layouts.nav')

On your nav.blade.php page, here could be your content:

<nav id="navbar"> Nav Item </nav>

Then finally, in your footer partial, you can close the opened divs up:

</div>{{--  Closes the #app id  --}}
</div>  {{--  Closes the Container class  --}} 
<script>Your JS links and sources</script>

So, in essence, what all these suggest is that within any file, if you call the file path correctly, you can use and

embed any partial from anywhere. Note, the (dot) indentation suggests a level deep down in the files structure. Which means, in your Views folder, this will be the structure of your subfolders:

- Views
   - layouts.blade.php
      - header.blade.php
      - nav.blade.php
      - footer.blade.php
   - home.blade.php