前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Laravel-添加后台模板AdminLte的实现方法

Laravel-添加后台模板AdminLte的实现方法

作者头像
砸漏
发布2020-10-20 14:43:38
2.7K0
发布2020-10-20 14:43:38
举报
文章被收录于专栏:恩蓝脚本

AdminLTE是一个很棒的单纯的由 HTML 和 CSS 构建的后台模板,在这片文章中,我将讲述如何将 AdminLTE 和 Laravel 优雅的整合在一起,而且我们可以通过 Bower 来及时的更新和管理 AdminLTE。

1、新建laravel项目

代码语言:javascript
复制
composer create-project laravel/laravel myapp --prefer-dist

2、使用前端包管理器添加AdminLte(可以使用npm或者yarn、bower),在项目根目录下执行如下命令:

代码语言:javascript
复制
yarn add admin-lte 

会在项目根目录下看到,node_modules\admin-lte\

3、将admin-lte文件夹复制到public目录下,开始使用:

首先按照laravel模板的方式建立layouts基础样式模板 default.balde.php, 将admin-lte下的starter.html内容复制到default中,

并将头尾侧边栏等公用部分放入不同的子模板_header _footer _left中,如图:

最后的default模板代码:(注意修改好导入样式和js文件的路径)

代码语言:javascript
复制
<!DOCTYPE html 
<html 
<head 
 <meta charset="utf-8" 
 <meta http-equiv="X-UA-Compatible" content="IE=edge" 
 <title 后台管理系统</title 
 <!-- Tell the browser to be responsive to screen width -- 
 <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport" 
 <!-- Bootstrap 3.3.6 -- 
 <link rel="stylesheet" href="/admin-lte/bootstrap/css/bootstrap.min.css" rel="external nofollow"  
 <!-- Font Awesome -- 
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="external nofollow"  
 <!-- Ionicons -- 
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" rel="external nofollow"  
 <!-- Theme style -- 
 <link rel="stylesheet" href="/admin-lte/dist/css/AdminLTE.min.css" rel="external nofollow"  
 <link rel="stylesheet" href="/admin-lte/dist/css/skins/skin-blue.min.css" rel="external nofollow"  
 <!--[if lt IE 9] 
 <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js" </script 
 <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js" </script 
 <![endif]-- 
</head 
<body class="hold-transition skin-blue sidebar-mini" 
<div class="wrapper" 
 @include('admin.layouts._header')
 @include('admin.layouts._left')
 @yield('content')
 @include('admin.layouts._footer')
 @include('admin.layouts._tip')
 <div class="control-sidebar-bg" </div 
</div 
<!-- jQuery 2.2.3 -- 
<script src="/admin-lte/plugins/jQuery/jquery-2.2.3.min.js" </script 
<!-- Bootstrap 3.3.6 -- 
<script src="/admin-lte/bootstrap/js/bootstrap.min.js" </script 
<!-- AdminLTE App -- 
<script src="/admin-lte/dist/js/app.min.js" </script 
</body 
</html 

项目中的其他页面就可以继承使用layouts模板了:

代码语言:javascript
复制
@extends('admin.layouts.default')
@section('content')
<div class="content-wrapper" 
 <section class="content-header" 
  <h1 
  Page Header
  <small 首页管理</small 
  </h1 
  <ol class="breadcrumb" 
  <li <a href="#" rel="external nofollow"  <i class="fa fa-dashboard" </i  Level</a </li 
  <li class="active" Here</li 
  </ol 
 </section 
 <section class="content" 
  <div class='row' 
 <div class='col-md-6' 
  <!-- Box1 -- 
  <div class="box box-primary" 
   <div class="box-header with-border" 
    <h3 class="box-title" 盒子一</h3 
    <div class="box-tools pull-right" 
     <button class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse" <i class="fa fa-minus" </i </button 
     <button class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove" <i class="fa fa-times" </i </button 
    </div 
   </div 
   <div class="box-body" 
    <table </table 
   </div 
   <div class="box-footer" 
    <form action='#' 
     <input type='text' placeholder='New task' class='form-control input-sm' / 
    </form 
   </div 
  </div 
 </div 
 </div 
 </section 
</div 

@stop

想要使用admin-lte自带的任何样式,直接复制那部分的页面代码粘贴到需要的位置即可,

在本地电脑上直接打开admin-lte下index.html就可以查看到所有的样式效果

本例最后达到的效果如图:

以上这篇Laravel-添加后台模板AdminLte的实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档