Php 是否有一种方法可以在Laravel blade中单独包含该部分?

Php 是否有一种方法可以在Laravel blade中单独包含该部分?,php,laravel-4,blade,php-include,Php,Laravel 4,Blade,Php Include,在laravel blade中扩展视图时,要有多个插入位置,可以按如下方式进行: <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_lib

在laravel blade中扩展视图时,要有多个插入位置,可以按如下方式进行:

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

这是app/view/layout/default.blade.php
{{HTML::script('js/jquery-2.1.3.min.js')}
{{HTML::script('js/angular.js')}
@收益率(“额外的库”)
@收益率('左菜单栏')
@产量(‘主要成分’)
然后,在使用布局时

@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
@extend(“layout.default”)
@第节(“额外图书馆”)
{{HTML::script('js/underline.js')}
@停止
@节(“左菜单栏”)
@停止
@节(“主要内容”)
测试
@停止
我想要的是一个类似的功能,当我不扩展,但包括另一个刀片到我的当前刀片。i、 例如:

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

这是app/view/layout/default.blade.php
{{HTML::script('js/jquery-2.1.3.min.js')}
{{HTML::script('js/angular.js')}
@包括('components.componentA.htmlComponent')
@包括('components.componentB.htmlComponent')
var app=angular.module('myTestingApp',[]).controller(“testing”,testingController);
功能测试控制器($scope){
@包括('components.componentA.angularCode')
@包括('components.componentB.angularCode')
}
其中componentA应该是一个包含anguarCode和htmlComponent的blade文件。我知道我可以将它们分为两个文件,但我想看看是否有办法将它们放在同一个文件中,因为它们密切相关。laravel blade中是否有默认功能来实现这一点

另外,如果你知道angularjs,这个例子说明了我为什么要把它们放在一起

将另一个刀片包含到我的当前刀片中

嗯,要在现有刀片文件中包含另一个刀片文件,肯定是@include标记来保存这一天。如果它仍然不能满足您的要求,您可以随时编写自己的方法


但是,整个过程对我来说似乎有点太复杂了。为什么不将JavaScript分成不同的控制器,然后使用调用相应的HTML,如文档底部的示例所示。

不确定,但您可以尝试一下

...
<body ng-app="myTestingApp">
    <div ng-controller="testing">
        @yield('componentA-html')
        @yield('componentB-html')
    </div>
    <script>
    var app = angular.module('myTestingApp', []).controller("testing", testingController);
    function testingController($scope) {
        @yield('componentA-angularCode')
        @yield('componentB-angularCode')
    }
    </script>
</body>
@include('components.componentA')
@include('components.componentB')
</html>

ComponentB blade的方法也一样

感谢您建议ng视图。我是Angularjs新手,没有注意到还有其他选项。但是,由于它正在从URL加载另一个页面,因此我需要另一个控制器来返回正确的视图?而且,它似乎正在运行中加载页面,我想在其中预加载所有页面。所以它似乎不适合我。我将尝试扩展刀片。好的,在这种情况下,你也可以看看哪些可以帮助你呈现静态内容。这里是一个非常简单的plnkr示例