3

TL;DR: What is the correct way to link to a stylesheet in Laravel 5?

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

I've moved my blade layout files to the new directory structure (resources/templates) and placed my CSS in the public/css/ folder.

When I load my route /test/ all I get is "Whoops, looks like something went wrong."

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.

The problem:

In my layouts, if I remove the following, the layouts work:

{{ HTML::style('css/bootstrap.min.css') }}
{{ HTML::style('css/style.css') }}

Question:

What is the correct location and syntax for Blade Stylesheet inclusion in Laravel 5 and what I should be using instead?

4

3 回答 3

8

HtmlBuilder已从 Laravel 的核心中删除,因此不再HTML::style()可用。

如果您想在 laravel 5 中使用它,请将以下内容添加到您的composer.json文件中,在require键下:

"laravelcollective/html": "~5.0"

另请注意,由于HTML::style()返回 HTML 代码,您不希望它转义。使用原始括号:

{!! HTML::style('css/style.css') !!}
于 2014-12-31T01:17:43.187 回答
0

添加到@joseph 的答案,对于不喜欢切换到新语法的用户,您可以使用

Blade::setRawTags('{{', '}}');

并继续使用旧语法。这几乎可以在任何地方设置,但更好的选择是服务提供商,比如 legacy service provide for l4 。您可以在laracasts找到关于此的进一步讨论,在那里您可以找到 taylor otwells 对此的想法。

于 2015-01-01T02:38:07.370 回答
0

If you want to use plain HTML then use like this-

    <link rel="stylesheet" href="/css/folder/style.css">
于 2016-02-06T14:01:17.973 回答