Laravel 4 Tutorial / Add_Twitter-Bootstrap
来源:互联网 发布:淘宝邻家好货 编辑:程序博客网 时间:2024/05/16 08:50
from:https://bitbucket.org/beni/laravel-4-tutorial/wiki/Add_Twitter-Bootstrap
The Twitter-Bootstrap is a simple front-end framework that is used in many web applications.
You can download the latest version at getbootstrap.com. Laravel also has a bootstrap-directory, but this has nothing to do with the Twitter-Bootstrap.
This chapter is based on the previous Using Templates chapter. To start directly, you have to download using-templates-package.
Add Bootstrap to your Application
To make the bootstrap available for our application we have to create some directories:
- /public/css
- /public/fonts
- /public/js
The downloaded bootstrap-package also has this directories somewhere inside. Just copy (extract) the files to the appropriate directories. In addition we download jQuery.com to supply it directly in our public js-directory. Now you should have following files in your public:
- /public/css/bootstrap.css
- /public/css/bootstrap.min.css
- /public/css/bootstrap-theme.css
- /public/css/bootstrap-theme.min.css
- /public/fonts/glyphicons-halflings-regular.eot
- /public/fonts/glyphicons-halflings-regular.svt
- /public/fonts/glyphicons-halflings-regular.ttf
- /public/fonts/glyphicons-halflings-regular.woff
- /public/js/bootstrap.js
- /public/js/bootstrap.min.js
- /public/js/jquery-1.11.1.min.js
Use Bootstrap in your Master-Template
We have to include the Bootstrap at our master template to supply it to all pages.
/app/views/layouts/master.blade.php:
<!DOCTYPE html><html> <head> <title> @section('title') Laravel 4 - Tutorial @show </title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- CSS are placed here --> {{ HTML::style('css/bootstrap.css') }} {{ HTML::style('css/bootstrap-theme.css') }} <style> @section('styles') body { padding-top: 60px; } @show </style> </head> <body> <!-- Container --> <div class="container"> <!-- Content --> @yield('content') </div> <!-- Scripts are placed here --> {{ HTML::script('js/jquery-1.11.1.min.js') }} {{ HTML::script('js/bootstrap.min.js') }} </body></html>
According to the Bootstrap-Help we add a meta-tag "viewport" for mobile devices. We can use {{ HTML::style('...') }} to add a css and {{ HTML::script('...') }} to add a javascript to our template. So we insert two css and two scripts.
To get this example working we need to add a padding for our body to show the menu correctly. To give the views the possibility to change the styles we add a styles section.
If you test the view, you will not see much changes. In the next step we add a main navigation-bar.
/app/views/layouts/master.blade.php:
<!DOCTYPE html><html> <head> <title> @section('title') Laravel 4 - Tutorial @show </title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- CSS are placed here --> {{ HTML::style('css/bootstrap.css') }} {{ HTML::style('css/bootstrap-theme.css') }} <style> @section('styles') body { padding-top: 60px; } @show </style> </head> <body> <!-- Navbar --> <div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Laravel</a> </div> <!-- Everything you want hidden at 940px or less, place within here --> <div class="collapse navbar-collapse"> <ul class="nav navbar-nav"> <li><a href="{{{ URL::to('') }}}">Home</a></li> </ul> </div> </div> </div> <!-- Container --> <div class="container"> <!-- Content --> @yield('content') </div> <!-- Scripts are placed here --> {{ HTML::script('js/jquery-1.11.1.min.js') }} {{ HTML::script('js/bootstrap.min.js') }} </body></html>
I don't want to explain all the elements here. You can look at the Bootstrap Help.
For the Home-Button we insert {{{ URL::to('') }}} to get automatic the correct link to our homepage.
You can test the new layout in your browser.
Hint: Sometimes the views are cached in Laravel, so the browser doesn't show the changes. You can try to delete the compiled views inside /app/storage/views/.
The bootstrap-package can also be found at the uploads.
The next chapter shows how to add a User Management.
- Laravel 4 Tutorial / Add_Twitter-Bootstrap
- Laravel 5.1.4 + Bootstrap 3.3.5 笔记二:Laravel 路由
- Laravel 5.1.4 + Bootstrap 3.3.5 笔记三:Laravel 中间件
- Laravel 5.1.4 + Bootstrap 3.3.5 笔记四:Laravel 控制器
- Laravel 5+ Bootstrap 4 分页器
- Laravel 5.1.4 + Bootstrap 3.3.5 笔记一:Laravel 环境搭建
- Bootstrap tutorial: A responsive design tutorial with Twitter Bootstrap 3
- Add Bootstrap to laravel 5
- PHP laravel系列之bootstrap美化
- tutorial 4
- AngularJS MySQL and Bootstrap Shopping List Tutorial - php
- [李景山php]每天laravel[005]-入口文件 bootstrap / app.php
- 如何在 Laravel 5.1 中使用 Laravel Elixir 集成安装 Bootstrap
- git 拖下laravel 代码后报错 Warning: require(D:\WWW\laravel\bootstrap/../vendor/autoload.php
- Laravel 4 Sitemap--动手写Laravel CMS
- Laravel教程:laravel 4安装及入门
- Laravel教程:laravel 4安装及入门
- bootstrap------4------
- java.lang.ClassCastException: 。。。$LayoutParams cannot be cast to android.widget.LinearLayout$Layout
- 全面理解面向对象的 JavaScript
- Android NDK (学习笔记五) —— java层和native层进行字符串的交互处理
- list常用函数的例子
- Android 利用sharepreference保存应用程序状态
- Laravel 4 Tutorial / Add_Twitter-Bootstrap
- C++ 容器及选用总结
- Android Design Support Library使用详解
- 传智播客Android7.16日入驻大广州
- Hibernate 的关系映射总结
- list的构造函数
- 仿凤凰时时彩代购平台源码[ASP+MSSQL]完整下载
- js Date对象的使用
- UCGUI自定义字库及显示汉字的程序