在刀片模板中包含CSS文件? [英] Including a css file in a blade template?
本文介绍了在刀片模板中包含CSS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Laravel刀片模板中包含一个CSS文件.
I want to include a css file in my Laravel blade template.
我尝试过:
@include(public_path('css/styles.css'))
但是它说视图不存在.它确实存在.
But it says view does not exist. It does exist.
如何包含CSS文件?
请注意,我知道这不是链接css文件的正确方法,但就我的用例而言,它是(我没有建立网站).
Please note, I know this is not the correct way to link css files, but for my use case it is (I'm not building a website).
推荐答案
@include
指令允许您从另一个视图中包括刀片视图,如下所示:
@include
directive allows you to include a Blade view from within another view, like this :
@include('another.view')
包括来自主版面的CSS或JS
<link href="{{ asset('css/styles.css') }}" rel="stylesheet">
<script type="text/javascript" src="{{ asset('js/scripts.js') }}"></script>
从子视图插入CSS或JS,请使用@push()
.
layout.blade.php
Incude CSS or JS from sub-view, use @push()
.
layout.blade.php
<html>
<head>
<!-- push target to head -->
@stack('styles')
@stack('scripts')
</head>
<body>
<!-- or push target to footer -->
@stack('scripts')
</body>
</html
view.blade.php
view.blade.php
@push('styles')
<link href="{{ asset('css/styles.css') }}" rel="stylesheet">
@endpush
@push('scripts')
<script type="text/javascript" src="{{ asset('js/scripts.js') }}"></script>
@endpush
这篇关于在刀片模板中包含CSS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文