[英]How can I include js files correspondes to render files in laravel blade template?
在我的Laravel應用中,我有以下代碼的app.blade.php
<html>
<body>
<div>
@yield('content')
</div>
<script src="{{ asset('jquery.min.js') }}" ></script>
<script src="{{ asset('bootstrap.min.js') }}" ></script>
</body>
</html>
我有幾個頁面,例如page1
, page2
等,每個頁面都呈現為page1.blade.php
等,這些頁面具有單獨的javascript文件,例如page1.js
, page2.js
。
page1.js
應包含在page1.blade.php
, page2.js
也應包含在page1.blade.php
。 如何為相應的刀片文件包括js文件?
我的page1.blade.php
是
@extends('layouts.app')
@section('content')
<section class="content-header">
<h1>
Page 1
</h1>
</section>
@endsection
app.blade.php
<html>
<body>
<div>
@yield('content')
</div>
<script src="{{ asset('jquery.min.js') }}" ></script>
<script src="{{ asset('bootstrap.min.js') }}" ></script>
@yield('script')
</body>
</html>
和page1.blade.php
@extends('layouts.app')
@section('content')
<section class="content-header">
<h1>
Page 1
</h1>
</section>
@endsection
@section('script')
<script src="{{ asset('page1.js') }}" ></script>
@endsection
您可以使用5.1版本之后的@stack方法。 有關詳細信息: https : //laravel.com/docs/5.7/blade#stacks
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.