smarty模板引擎总结六配置网站title,keywords,description
前台样式配置
作用:配置前台一些数据 title,keys,网站的描述,一些css样式
在smarty初始化文件 smarty.inc.php
$smarty->config_dir = "./conf"; // 前台样式配置目录
放在:/conf/ 目录
文件命名: XXXXX.conf
[模块名]
配置项名=值
配置项名=值
[模块名2]
配置项名=值
配置项名=值
[index]
title = 欣才商城
keys = 欣才电脑 南京欣才电脑
description = 南京欣才
[index2]
title = 欣才商城2
keys = 欣才电脑2 南京欣才电脑2
description = 南京欣才2
注意: 不需要加 ; "" '' 这些符号!
使用:
在模版文件的头部引入配置文件
{config_load file="XXXX.conf" section="模块名"}
配置变量的输出
1.{#配置项名#}
2.{$smarty.config.配置项名}
注意:
1. 路径计算
2. section:模块名 如果不设置,调用公共,如果设置:section对应的模块
1.在/smarty/下建立一个conf文件夹,在其下建立一个common.conf文件内容如下
2.Smarty.inc.php增加$smarty->config_dir = "./conf";
<?phprequire("./Autoloader.php");//require()引入smarty自动加载类文件Smarty_Autoloader::register(); //把register()方法注册到自动加载类函数里面$smarty = new SmartyBC();//创建smarty对象//smarty运行环境的配置$smarty->template_dir = "./template"; //配置模版目录$smarty->compile_dir = "./comp";//配置编译目录$smarty->cache_dir = "./cache";//配置缓存目录$smarty->config_dir = "./conf";//前台样式配置目录 ?>3.index.html头部增加{config_load file="common.conf" section="index"}
{config_load file="common.conf" section="index"} <!DOCTYPE html> <html> <head><title>{#title#}</title><meta charset="utf-8"><meta name="keywords" content="{$smarty.config.keywords}"><meta name="description" content="{$smarty.config.description}"><script type="text/javascript" src="./public/Js/xxx.js"></script><link type="text/css" rel="stylesheet" href="./public/Css/common.css" /></head> <body><!--include引入模版页面的路径注意,header.html,footer.html,和index.html同级,不用./template/header.html-->{include file="header.html"}<div class="body"><h1>这是网站主体部分</h1></div>{include file="footer.html"} </body> </html>其他部分代码不变,
4.header.html
<!DOCTYPE html> <html> <head><title>网站头部</title><meta charset="utf-8"><meta name="keywords" content=""><script type="text/javascript" src="./public/Js/xxx.js"></script><link type="text/css" rel="stylesheet" href="./public/Css/common.css" /></head> <body><div class="head">这是网站头部</div> </body> </html>5.footer.html
<!DOCTYPE html> <html> <head><title>网站底部</title><meta charset="utf-8"><meta name="keywords" content=""><script type="text/javascript" src="./public/Js/xxx.js"></script><link type="text/css" rel="stylesheet" href="./public/Css/common.css" /></head> <body><div class="foot">这是网站底部</div> </body> </html>6.index.php
转载于:https://blog.51cto.com/it5808/1709502
总结
以上是生活随笔为你收集整理的smarty模板引擎总结六配置网站title,keywords,description的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 靠人不如靠自己啊
- 下一篇: easyui tab