当在laravel刀片中扩展视图时,要有多个插入位置,可以这样做:
<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>
然后,在使用布局时,
@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
我想要的是类似的功能,当我没有延伸但是在我当前的刀片中包含另一个刀片时。就像这样:
<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>
其中componentA应该是包含anguarCode和htmlComponent的刀片文件。我知道我可以将它们分成2个文件,但是我想知道是否有办法将它们放在同一个文件中,因为它们密切相关。 laravel刀片中是否有默认功能来实现这一目标?
P.S。这个例子说明了为什么我想把它们放在一起,如果你知道angularjs。
答案 0 :(得分:1)
将另一个刀片包含在我当前的刀片中
好吧,要将另一个刀片文件包含在现有文件中,它肯定是 @include 标记来节省一天。如果它仍然不能满足您的要求,您始终可以通过extending Blade编写自己的方法。
然而,整件事对我来说似乎有点过于复杂。为什么不将JavaScript分成不同的控制器,然后使用ng-view来调用相应的HTML,如文档底部的示例所示。
答案 1 :(得分:0)
不确定,但您可以尝试
...
<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>
您的componentA刀片应该是
@section('componentA-html')
html for A
@endsection
@section('componentA-angularCode')
angularCode for A
@endsection
使用compomentB刀片的方法相同