twitter-bootstrap 在 Laravel 4 中使用 Bootstrap 的最佳方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23919486/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 20:49:20  来源:igfitidea点击:

Best method to use Bootstrap in Laravel 4

twitter-bootstraplaravel-4

提问by Thom

I am using now Laravel 4,
What is the best method to use bootstrap for my site?
Is there some stuff I need to change and where do I put the css files?

我现在正在使用 Laravel 4,
为我的网站使用引导程序的最佳方法是什么?
有什么我需要改变的东西,我应该把 css 文件放在哪里?

Someone said that I need to use the composerand another said that I need to use the artisan

有人说我需要使用composer另一个说我需要使用artisan

Thanks

谢谢

回答by Antonio Carlos Ribeiro

Some things you must know about Laravel:

关于 Laravel 你必须知道的一些事情:

It has directly nothing to do with your front end, including Twitter Bootstrap.

它与您的前端(包括 Twitter Bootstrap)没有直接关系。

Where you put your files is entirely up to you, but the public folder is (usually) where your public viewable files must go.

您将文件放在哪里完全取决于您,但公共文件夹(通常)是您的公共可见文件必须存放的地方。

CSS and JavaScript files are directly downloaded by browser, so those files should be in your public folder.

CSS 和 JavaScript 文件由浏览器直接下载,因此这些文件应该在您的公共文件夹中。

To download/use Bootstrap you have some options:

要下载/使用 Bootstrap,您有一些选择:

1) Go to http://getbootstrap.com/and download it.

1)http://getbootstrap.com/下载。

2) Use bower (https://github.com/bower/bower) to download it for you.

2)使用 bower ( https://github.com/bower/bower) 为您下载。

3) If you are planning using a Bootstrap template, usually those already come with Bootstrap.

3)如果您计划使用 Bootstrap 模板,通常那些已经随 Bootstrap 提供的模板。

4) Use a CDN, like http://www.bootstrapcdn.com/

4) 使用 CDN,例如http://www.bootstrapcdn.com/

I, personally, use bower, those are the steps you can follow to install and use it:

我个人使用 bower,您可以按照以下步骤安装和使用它:

Install it

安装它

[sudo] npm install bower

Create a .bowerrcfile in your project dir, which tells bower where to download your packages:

.bowerrc在你的项目目录中创建一个文件,它告诉 bower 在哪里下载你的包:

{
    "directory": "public/bower"
}

Create a bower.jsonfile, which holds your installed packages:

创建一个bower.json文件,其中包含已安装的软件包:

{
  "name": "YourApp.com",
  "dependencies": {
  }
}

Then you just need to install your packages using it:

然后你只需要使用它安装你的软件包:

bower install bootstrap -S
bower install jquery -S

And you can also use it to find packages

你也可以用它来查找包

bower search google-code-prettify

After installing bootstrap, your css files would be located at:

安装引导程序后,您的 css 文件将位于:

public/bower/bootstrap/dist/css/

In Laravel there are many ways of including your assets, this is one of those, using Blade as you view compiler:

在 Laravel 中有很多方法可以包含您的资产,这是其中一种,在查看编译器时使用 Blade:

<link href="{{ asset('bower/bootstrap/dist/css/bootstrap.min.css') }}" rel="stylesheet">

回答by Adrian Enriquez

Here's the approach if you don't want to use bower.

如果您不想使用 bower,这里是方法。

  • Download bootstrap and extract the contents inside public/components/

  • Using Blade as your view compiler, use it like this:

  • 下载bootstrap并解压里面的内容 public/components/

  • 使用 Blade 作为你的视图编译器,像这样使用它:



<link href="{{ asset('components/bootstrap/dist/css/bootstrap.min.css') }}" rel="stylesheet">

or like this

或者像这样

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

回答by John Owen Chile

You can just include it on your app with composer:

您可以使用 Composer 将其包含在您的应用程序中:

composer require twbs/bootstrap

作曲家需要 twbs/bootstrap