smarty模板引擎总结六配置网站title,keywords,description
前臺樣式配置
作用:配置前臺一些數(shù)據(jù) title,keys,網(wǎng)站的描述,一些css樣式
? ? ?在smarty初始化文件 smarty.inc.php
? ? ?$smarty->config_dir ? ?= "./conf"; // 前臺樣式配置目錄
? ? ?放在:/conf/ ?目錄
? ? ?文件命名: ?XXXXX.conf
? ? ?[模塊名]
? ? ?配置項(xiàng)名=值
? ? ?配置項(xiàng)名=值
? ? ?[模塊名2]
? ? ?配置項(xiàng)名=值
? ? ?配置項(xiàng)名=值
[index]
title = 欣才商城
keys ?= 欣才電腦 ?南京欣才電腦
description = 南京欣才
[index2]
title = 欣才商城2
keys ?= 欣才電腦2 ?南京欣才電腦2
description = 南京欣才2
? ??注意: 不需要加 ; "" '' ?這些符號!
? ? ?使用:
在模版文件的頭部引入配置文件
{config_load file="XXXX.conf" section="模塊名"}
? ? ?配置變量的輸出
1.{#配置項(xiàng)名#}
2.{$smarty.config.配置項(xiàng)名}
? ? ?注意:
1. 路徑計算
2. section:模塊名 如果不設(shè)置,調(diào)用公共,如果設(shè)置:section對應(yīng)的模塊
1.在/smarty/下建立一個conf文件夾,在其下建立一個common.conf文件內(nèi)容如下
2.Smarty.inc.php增加$smarty->config_dir = "./conf";
<?phprequire("./Autoloader.php");//require()引入smarty自動加載類文件Smarty_Autoloader::register();?//把register()方法注冊到自動加載類函數(shù)里面$smarty?=?new?SmartyBC();//創(chuàng)建smarty對象//smarty運(yùn)行環(huán)境的配置$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>這是網(wǎng)站主體部分</h1></div>{include?file="footer.html"} </body> </html>其他部分代碼不變,
4.header.html
<!DOCTYPE?html> <html> <head><title>網(wǎng)站頭部</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">這是網(wǎng)站頭部</div> </body> </html>5.footer.html
<!DOCTYPE?html> <html> <head><title>網(wǎng)站底部</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">這是網(wǎng)站底部</div> </body> </html>6.index.php
轉(zhuǎn)載于:https://blog.51cto.com/it5808/1709502
總結(jié)
以上是生活随笔為你收集整理的smarty模板引擎总结六配置网站title,keywords,description的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 靠人不如靠自己啊
- 下一篇: 数据库 三范式最简单最易记的解释