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编辑器来显示内容,但是遇到了一个问题就是当下拉页面到一定距离之后,页面上方的导航栏会被内容遮盖. 二 ...
随机推荐
- Sqlite清空表数据
delete from TableName; //清空数据 where name ='TableName';//自增长ID为0
- 用sc命令查询系统状态
用sc命令查询系统状态 sc query 语法 sc query - Enumerates status for active services & driver ...
- python发送邮件方法总结
python中email模块使得处理邮件变得比较简单,今天着重学习了一下发送邮件的具体做法,这里写写自己的的心得,也请高手给些指点. 一.相关模块介绍 发送邮件主要用到了smtplib和ema ...
- Event sender
Sometimes it is convenient to know which widget is the sender of a signal. For this, PyQt4 has these ...
- Drawing points
A point is the most simple graphics object that can be drawn. It is a small spot on the window. #!/u ...
- filter中的dispatcher解析
两种include方式 我自己写了一个original.jsp,另外有一个includedPage.jsp,我想在original.jsp中把includedPage.jsp引进来有两种方式: 1.& ...
- Java Callable 与 Future
- How vacuum template0
[pg@h1 ~]$ vacuumdb --freeze template0 vacuumdb: could not connect to database template0: FATAL: dat ...
- 控制器中添加DB类才可以操作数据库表中的数据
必须使用DB: use DB;
- Linux命令-文件处理命令:cat
cat /etc/issue 查看etc目录下面的issue文件内容(issue是linxu系统的欢迎文件) cat -n /etc/issue 查看文件内容的时候显示行号 tac /etc/issu ...