在Laravel 5或4.3中包括CSS [英] Including CSS in Laravel 5 or 4.3
问题描述
TL; DR:在Laravel 5中链接到样式表的正确方法是什么?
背景: 我使用的是Laravel 4.3(5)的开发版本,因为我想使用Socialite,并且从一开始就进行开发是有意义的.我在从4.2传输模板时遇到问题
Background: I'm using the dev version of Laravel 4.3 (5) because I want to use Socialite, and it makes sense to develop with that from the start. I am having a problem getting templates transferred from 4.2
我已经将刀片布局文件移动到新的目录结构(资源/模板)中,并将CSS放置在public/css/文件夹中.
I've moved my blade layout files to the new directory structure (resources/templates) and placed my CSS in the public/css/ folder.
当我加载路线/test/时,我得到的只是呜呼,好像出了点问题."
When I load my route /test/ all I get is "Whoops, looks like something went wrong."
出于测试目的,我从布局中删除了所有刀片布局语法-原始HTML有效,但是没有样式(因为没有链接的样式表).这告诉了我路线,视图和控制器的工作方式.
For testing purposes I've removed all blade layout syntax from my layouts - the raw HTML works, but there is no styling (as there is no linked stylesheet). That tells me the routes, views and controllers work.
问题:
在我的布局中,如果删除以下内容,则这些布局将起作用:
In my layouts, if I remove the following, the layouts work:
{{ HTML::style('css/bootstrap.min.css') }}
{{ HTML::style('css/style.css') }}
问题:
Laravel 5中包含刀片样式表的正确位置和语法是什么?我应该使用什么?
What is the correct location and syntax for Blade Stylesheet inclusion in Laravel 5 and what I should be using instead?
推荐答案
HtmlBuilder
已从Laravel的核心中删除,因此HTML::style()
不再可用.
The HtmlBuilder
has been removed from Laravel's core, so HTML::style()
is no longer available.
如果您想在laravel 5中使用它,请将以下内容添加到您的composer.json
文件,在require
键下:
If you want to use it in laravel 5, add the following to your composer.json
file, under the require
key:
"laravelcollective/html": "~5.0"
还请注意,由于HTML::style()
返回HTML代码,因此您不希望其转义.使用原始括号:
Also note, since HTML::style()
returns HTML code, you don't want it escaped. Use the raw brackets:
{!! HTML::style('css/style.css') !!}
这篇关于在Laravel 5或4.3中包括CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!