templates/gentelella/base.tpl
display('tpl/head.tpl'); ?> display('tpl/nav.tpl'); ?>
// 这是是中间的功能显示,index, network, about, 等等。
display('tpl/********'); ?>
display('tpl/foot.tpl'); ?>
display('tpl/tail.tpl'); ?>
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 .= '
'.$key.' '."\n"; // code indent 增加缩进 $ret .= fillBlank($level+1); $ret .= ' '."\n"; // 缩进 $ret .= fillBlank($level); $ret .= ''."\n"; } else { // 如果不存在,调用 fillBlank 函数,其实这个函数就是根据你的 level 决定ret的缩进 $ret .= fillBlank($level); $ret .= ' '.$key.''."\n"; } } return $ret; } // 他把对应的 nav 索引下的数据作为第一个参数,级别为1, active 为home, 当前的页面的php文件 $smarty->assign("recursiveNav", recursiveNav($tplconf['nav'], $level, $active, $currentPage)); 最终这个模板的实现是在 templates/gentelella/nav.tpl 内。