欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

smarty模板引擎总结六配置网站title,keywords,description

发布时间:2024/4/14 编程问答 48 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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文件内容如下


[index] title = 南京红牛装饰官网-南京装修公司,南京装饰公司,南京家装公司 keywords  = 南京装修公司,南京装饰公司,南京家装公司,南京红牛装饰 description = 南京红牛装饰成立于1998年,先后被评为十大南京装修公司,江苏省明星企业,有装修资质的南京装饰公司,主营:南京家庭装修,南京新房装修,南京老房装修,南京别墅装修设计等。 [index2] title = 标点装修网 keywords = 标点装修网,标点金管家,装修监理,家装第三方平台,装饰公司 description = 标点装修网是一家免费专门的装修监理网络公司

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

<?phprequire("./Smarty.inc.php");//引入smarty的初始化文件$smarty->display("index.html"); //这行代码要放到最后否则会报错?>

转载于:https://blog.51cto.com/it5808/1709502

总结

以上是生活随笔为你收集整理的smarty模板引擎总结六配置网站title,keywords,description的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。