EmWebAdmin 导航栏分析
templates/gentelella/base.tpl
<!DOCTYPE html>
<html lang="en">
<!-- Smarty lib -->
<!-- 这里就调用了 templates/smarty/config/tplconf.json -->
<?php require('tpl/SmartySetup.php'); ?>
<!-- /Smarty lib -->
<!-- head -->
<head>
<!-- 这里就只有一句 <title>{$tplconf["appName"]}</title> -->
<?php $smarty->display('tpl/head.tpl'); ?>
</head>
<!-- /head -->
<body class="nav-md">
<div class="container body">
<div class="main_container">
<!-- left content -->
<!-- 调用导航栏模板 -->
<?php $smarty->display('tpl/nav.tpl'); ?>
<!-- /left content -->
<!-- right content -->
// 这是是中间的功能显示,index, network, about, 等等。
<?php $smarty->display('tpl/********'); ?>
<!-- /right content -->
<!-- footer content -->
<?php $smarty->display('tpl/foot.tpl'); ?>
<!-- /footer content -->
</div>
</div>
<!-- JavaScript -->
<?php $smarty->display('tpl/tail.tpl'); ?>
<!-- /JavaScript -->
</body>
</html>
EmWebAdmin 的导航栏的配置文件是 templates/smarty/config/tplconf.json 文件
// 这个文件的解析是在 templates/smarty/preprocess/SmartySetup.php 里面被调用然后解析
// NOTE: Smarty has a capital 'S'
require_once('smarty/Smarty.class.php');
$smarty = new Smarty();
// $smarty->debugging = true;
// template configures
$tplconf = json_decode(file_get_contents("config/tplconf.json"), true);
$smarty->assign('tplconf', $tplconf);
// system configures
$sysconf = json_decode(file_get_contents("config/sysconf.json"), true);
$smarty->assign('sysconf', $sysconf);
// custom configures
$cusconf = json_decode(file_get_contents("config/cusconf.json"), true);
$smarty->assign('cusconf', $cusconf);
include "tpl/tplFuncs.php";
真正解析 的地方在 templates/smarty/preprocess/tplFuncs.php 里面
$level = 1;
$active = "Home";
$currentPage = end(explode('/', $_SERVER['PHP_SELF']));
// end 返回的值里面数组的最后一个值
// explode 是以前面一个字符串作为分隔符将后面的字符串进行分割
// PHP_SELF 是当前页面的链接
// 所以这个是返回当前页面的 php 文件
/**
* @jsonData: nav data as JSON data format
* @level: indent level
* @active: Classify for php file
* @currentPage: current php file
*/
Function recursiveNav($jsonData, $level, $active, $currentPage)
{ // ret 变量存储了所有的 导航栏的文字的显示以及链接
$ret = ""; // 循环 nav 索引内的所有对应的子索引
foreach( $jsonData as $key => $value ) {
if( isset( $value['subitem'] ) ) {
// 判断 子索引对应的内容中有没有 subitem
// with the drop-down options
// 缩进的控制
$ret .= fillBlank($level);
$ret .= '<li';
if ($key == $active) $ret .= ' class="active"';
$ret .= '><a><i class="fa fa-'.$value["icon"].'"></i> '.$key.' <span class="fa fa-chevron-down"></span></a >'."\n";
// code indent 增加缩进
$ret .= fillBlank($level+1);
$ret .= '<ul class="nav child_menu">'."\n";
// recursive callback 子目录
$ret .= recursiveNav($value['subitem'], $level+2, $active, $currentPage);
// 缩进
$ret .= fillBlank($level+1);
$ret .= '</ul>'."\n";
// 缩进
$ret .= fillBlank($level);
$ret .= '</li>'."\n";
} else {
// 如果不存在,调用 fillBlank 函数,其实这个函数就是根据你的 level 决定ret的缩进
$ret .= fillBlank($level);
$ret .= '<li';
// 如果对应有 link 索引, 并且 link 索引对应的值存在 那么添加链接
if ($currentPage == $value['link'])
$ret .= ' class="current-page"';
$ret .= '><a href="'.$value['link'].'"><i class="fa fa-'.$value['icon'].'"></i>'.$key.'</a></li>'."\n";
}
}
return $ret;
}
// 他把对应的 nav 索引下的数据作为第一个参数,级别为1, active 为home, 当前的页面的php文件
$smarty->assign("recursiveNav", recursiveNav($tplconf['nav'], $level, $active, $currentPage));
最终这个模板的实现是在 templates/gentelella/nav.tpl 内。
<div class="col-md-3 left_col">
<div class="left_col scroll-view">
<div class="navbar nav_title" style="border: 0;" align="center">
<a href="index.php"><img src="images/webadmin.png" class="img-rounded"></a>
</div>
<div class="clearfix"></div>
<br />
<!-- sidebar menu -->
<div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
<div class="menu_section">
<ul class="nav side-menu">
{$recursiveNav} <!-- 模板变量 -->
</ul>
</div>
</div>
<!-- /sidebar menu -->
</div>
</div>
EmWebAdmin 导航栏分析的更多相关文章
- android 自己定义状态栏和导航栏分析与实现
效果 android 4.4之后,系统是支持自己定义状态栏和导航栏的.举个最典型的样例就是bilibiliclient了(iOS版本号和android版本号能用两套全然不一样符合各自系统的设计ui,良 ...
- Bootstrap导航栏navbar源码分析
1.本文目地:分析bootstrap导航栏及其响应式的实现方式,提升自身css水平 先贴一个bootstrap的导航栏模板 http://v3.bootcss.com/examples/navbar- ...
- 原生JS实现全屏切换以及导航栏滑动隐藏及显示——重构前
思路分析: 向后滚动鼠标滚轮,页面向下全屏切换:向前滚动滚轮,页面向上全屏切换.切换过程为动画效果. 第一屏时,导航栏固定在页面顶部,切换到第二屏时,导航条向左滑动隐藏.切换回第一屏时,导航栏向右滑动 ...
- 使用vue给导航栏添加链接
如下面的导航栏,使用vue技术给该导航栏增加链接: js代码为: navigation:function(){ new Vue({ el: '#navUl', data: { menuData:{ ' ...
- 解析导航栏的url--selnium,beautifulsoup实战
前段时间做ui自动化测试的时候,导航栏菜单始终有点问题,最后只好直接获取到url,然后直接使用driver.get(url)进入页面: 包括做压测的时候,比如我要找出所有报表菜单的url,这样不可能手 ...
- ViewPager+GridView实现首页导航栏布局分页效果
如图是效果图用ViewPager+GridView实现首页导航栏布局分页效果来实现的效果 Demo下载地址:http://download.csdn.net/detail/qq_29774291/96 ...
- iOS解决隐藏导航栏后,打开照片选择器后导航栏不显示的问题以及更换导航栏背景色
问题描述: 遇到一种情况,在一个控制器上(隐藏了导航栏),打开照片选择器 UIImagePickerController后,照片选择器头部一片空白,且上滑相册时,信息会有错乱效果. 原因分析: 通过查 ...
- android布局学习-使用FrameLayout和LinearLayout制作QQ空间底部导航栏
[声明:本博客通过学习“J灬叶小超 ”博客而写,链接:http://www.cnblogs.com/yc-755909659/p/4288260.html] --------------------- ...
- 在mui中遇到的内容覆盖导航栏的问题
一.问题描述: 公司项目中为了让内容以页面的形式显示,并要格式化页面内容,采用了百度的UEditor编辑器来显示内容,但是遇到了一个问题就是当下拉页面到一定距离之后,页面上方的导航栏会被内容遮盖. 二 ...
随机推荐
- C++标准库 bitset
本文地址:http://www.cnblogs.com/archimedes/p/cpp-bitset.html,转载请注明源地址. 有些程序要处理二进制位的有序集,每个位可能包含 0(关)1(开)值 ...
- python 下载安装setuptools及pip应用
1.首先下载python安装程序,下载地址:https://www.python.org/download/releases/2.7.8/ 如下图: 因为我的机器是32位的就选择了Windows x8 ...
- java笔试题(5)
1.Comparable和Comparator接口是干什么的?列出它们的区别. Java提供了只包含一个compareTo()方法的Comparable接口.这个方法可以个给两个对象排序.具体来说,它 ...
- sql server 批量导出存储过程
sys.syscomments:包含数据库中每个视图.规则.默认值.触发器.CHECK 约束.DEFAULT 约束和存储过程的项.text 列包含原始的 SQL 定义语句.(简单点说,这个系统表存储了 ...
- (转)一个非常好的akka教程
akka系列文章目录 akka学习教程(十四) akka分布式实战 akka学习教程(十三) akka分布式 akka学习教程(十二) Spring与Akka的集成 akka学习教程(十一) akka ...
- Python——管理属性(1)
管理属性 这里将展开介绍前面提到的[属性拦截]技术.包含下面内容: [1]__getattr__和__setattr__方法.把没有定义的属性获取和全部的属性赋值指向通用的处理器方法 [2]__get ...
- Trie树统计单词前缀
输入 输入的第一行为一个正整数n.表示词典的大小,其后n行,每一行一个单词(不保证是英文单词,也有可能是火星文单词哦).单词由不超过10个的小写英文字母组成,可能存在同样的单词.此时应将其视作不同的单 ...
- [Big Data] Week 5 A (Advance)
Question 1 Consider the diagonal matrix M = 1 0 0 0 2 0 0 0 0 . Compute its Moore-Penrose pseudoinve ...
- SQLServer 之 聚合函数
一.聚合函数介绍 1.聚合函数最常用的: (1) COUNT:求个数 count函数用于计算满足条件的数据项数,返回int数据类型的值. [1] 语法结构:COUNT( {[[ all | disti ...
- Tetris
he Tetris game is one of the most popular computer games ever created. The original game was designe ...