laravel 在刀片模板中包含 css 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45279612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Including a css file in a blade template?
提问by panthro
I want to include a css file in my Laravel blade template.
我想在我的 Laravel 刀片模板中包含一个 css 文件。
I've tried:
我试过了:
@include(public_path('css/styles.css'))
But it says view does not exist. It does exist.
但它说视图不存在。它确实存在。
How can I include a css file?
如何包含 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).
请注意,我知道这不是链接 css 文件的正确方法,但对于我的用例来说是(我不是在构建网站)。
回答by Wahyu Kristianto
@include
directive allows you to include a Blade viewfrom within another view, like this :
@include
指令允许您从另一个视图中包含 Blade视图,如下所示:
@include('another.view')
Include CSS or JS from master layout
从主布局中包含 CSS 或 JS
<link href="{{ asset('css/styles.css') }}" rel="stylesheet">
<script type="text/javascript" src="{{ asset('js/scripts.js') }}"></script>
Incude CSS or JS from sub-view, use @push()
.
从子视图包含 CSS 或 JS,使用@push()
.
layout.blade.php
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
视图.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
回答by Wahyu Kristianto
if your css file in public/css use :
如果您的 css 文件在 public/css 中使用:
<link rel="stylesheet" type="text/css" href="{{ asset('css/style.css') }}" >
if your css file in another folder in public use :
如果您的 css 文件位于公共使用的另一个文件夹中:
<link rel="stylesheet" type="text/css" href="{{ asset('path/css/style.css') }}" >
回答by madpoet
As you said this is a very bad way to do so laravel doesn't have that functionality AFAIK.
正如您所说,这是一种非常糟糕的方法,因此laravel 没有AFAIK 的功能。
However blade can run plain php so you can do like this if you really need to:
然而,blade 可以运行普通的 php,所以如果你真的需要,你可以这样做:
<?php include public_path('css/styles.css') ?>
回答by Tjeu Moonen
In layouts.app.blade
(End of head)
在 layouts.app.blade
(头尾)
<head>
@include('layouts.includes.css.extracss')
</head>
blade file layouts.includes.css.extracss
刀片文件 layouts.includes.css.extracss
<style type="text/css">
your css
</style>
回答by gbalduzzi
<link rel="stylesheet" href="{{ URL::asset('css/styles.css') }}">
It will search for the file in your project public
folder
它将在您的项目public
文件夹中搜索文件
回答by AddWeb Solution Pvt Ltd
You should try this :
你应该试试这个:
{{ Html::style('css/styles.css') }}
OR
或者
<link href="{{ asset('css/styles.css') }}" rel="stylesheet">
Hope this help for you !!!
希望这对你有帮助!!!
回答by Hadie Danker
Work with this code :
使用此代码:
{!! include ('css/app.css') !!}
回答by purvisha thakarar
include the css file into your blade template in laravel
将 css 文件包含到 Laravel 中的刀片模板中
- move css file into public->css folder in your laravel project.
- use
- 将 css 文件移动到 Laravel 项目中的 public->css 文件夹中。
- 用
so cssis applied in a blade.php file.
所以css被应用在一个blade.php文件中。