Is there a way I can separately include section in Laravel blade?

When extending a view in laravel blade, to have multiple places of inserting, it can be done as something like this:

<html>
<head>
    <title>This is app/view/layout/default.blade.php</title>
    {{ HTML::script('js/jquery-2.1.3.min.js') }}
    {{ HTML::script('js/angular.js') }}
    @yield('extra_libraries')
</head>
<body>
    <div class="left-menu-bar">
        @yield('left-menu-bar')
    </div>
    <div class="main-content">
        @yield('main-content')
    </div>
</body>
</html>

Then, when using the layout,

@extend ("layout.default")
@section('extra_libraries')
    {{ HTML::script('js/underscore.js') }}
@stop
@section('left-menu-bar')
    <a href="http://www.google.com/">testing button</a>
@stop
@section('main-content')
    testing
@stop

What I want is a similar function when I am not extending but to include another blade into my current blade. i.e. something like this:

<html>
<head>
    <title>This is app/view/layout/default.blade.php</title>
    {{ HTML::script('js/jquery-2.1.3.min.js') }}
    {{ HTML::script('js/angular.js') }}
</head>
<body ng-app="myTestingApp">
    <div ng-controller="testing">
        @include('components.componentA.htmlComponent')
        @include('components.componentB.htmlComponent')
    </div>
    <script>
    var app = angular.module('myTestingApp', []).controller("testing", testingController);
    function testingController($scope) {
        @include('components.componentA.angularCode')
        @include('components.componentB.angularCode')
    }
    </script>
</body>
</html>

where componentA should be a blade file containing both anguarCode and htmlComponent. I know I can separate them into 2 files, but I want to see if there is a way to put them in the same file as they are closely related. Is there default function in laravel blade to achieve this?


Source: php

Leave a Reply