How to include a sub-view in Blade templates?

后端 未结 4 1196
日久生厌
日久生厌 2020-11-28 12:46

I am trying to set up a site using laravel, but I\'m really having trouble with basic things that the documentation just doesn\'t cover.

In this case, I see that it

4条回答
  •  无人及你
    2020-11-28 12:57

    You can use the blade template engine:

    @include('view.name') 
    

    'view.name' would live in your main views folder:

    // for laravel 4.X
    app/views/view/name.blade.php  
    
    // for laravel 5.X
    resources/views/view/name.blade.php
    

    Another example

    @include('hello.world');
    

    would display the following view

    // for laravel 4.X
    app/views/hello/world.blade.php
    
    // for laravel 5.X
    resources/views/hello/world.blade.php
    

    Another example

    @include('some.directory.structure.foo');
    

    would display the following view

    // for Laravel 4.X
    app/views/some/directory/structure/foo.blade.php
    
    // for Laravel 5.X
    resources/views/some/directory/structure/foo.blade.php
    

    So basically the dot notation defines the directory hierarchy that your view is in, followed by the view name, relative to app/views folder for laravel 4.x or your resources/views folder in laravel 5.x

    ADDITIONAL

    If you want to pass parameters: @include('view.name', array('paramName' => 'value'))

    You can then use the value in your views like so

    {{$paramName}}

提交回复
热议问题