使用 Composer 在 Laravel 4 中加载 css/js 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15855033/
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
Load css/js files in Laravel 4 with Composer?
提问by Jakemmarsh
I'm working on creating a new project in Laravel 4. I have a tiny bit of experience in Laravel 3, in which I got used to the assets system. I'm now having a lot of trouble figuring out how to load CSS and JS files in the new system.
我正在 Laravel 4 中创建一个新项目。我在 Laravel 3 中有一点经验,在那里我习惯了资产系统。我现在在弄清楚如何在新系统中加载 CSS 和 JS 文件时遇到了很多麻烦。
I believe I should be using Composer PHP, but I'm not sure how. Where do I put the actual .css and .js files? And then how do I load them with Composer to be utilized in the Laravel project?
我相信我应该使用 Composer PHP,但我不确定如何使用。我应该把实际的 .css 和 .js 文件放在哪里?然后我如何使用 Composer 加载它们以在 Laravel 项目中使用?
I know there are outside plugins like Best Asset, etc. that are written to replicate the Assets system of Laravel 3, but I was hoping to understand the new system and not have to use an outside plugin.
我知道有一些外部插件,如 Best Asset 等,它们是为了复制 Laravel 3 的资产系统而编写的,但我希望了解新系统,而不必使用外部插件。
Any help? Thanks.
有什么帮助吗?谢谢。
回答by Barryvdh
You don't need Composer for your css/js assets. You can use assets pretty much the same as with Laravel 3
您的 css/js 资产不需要 Composer。您可以使用与 Laravel 3 几乎相同的资源
You can just place them in your public folder and reference them in your views. You can use plain html, or use the HtmlBuilder: HTML::style('style.css')
and HTML::script('script.js')
您可以将它们放在您的公用文件夹中并在您的视图中引用它们。您可以使用纯 html,或使用 HtmlBuilder:HTML::style('style.css')
和HTML::script('script.js')
回答by Dexter_ns88
You must take care of case sensitive.
This class must write with uppercase.
您必须注意区分大小写。
这个类必须用大写写。
HTML::style('style.css');
HTML::script('script.js');
Laravel stylesheets and javascript don't load for non-base routes