smarty高级部分包括缓存机制和配置文件的调用

下面是代码实现:

文件一,配置文件:

#全局变量
title="网站主页"
content="一个网站的主体部分" #在news中
[news]
title="新闻页面"
content="新闻内容" #在forum中
[news]
title="论坛页面"
content="论坛内容"

文件二,php文件:

<?php
require("Smarty.class.php");
$smarty = new Smarty();
$smarty -> template_dir = "./templates"; //模板存放目录
$smarty -> compile_dir = "./templates_c"; //编译目录
$smarty -> cache_dir = "./cache"; //缓存目录
$smarty -> config_dir = "./configs"; //缓存目录 $smarty -> caching = 1;//打开缓存功能
$smarty -> cache_lifetime = 300;//缓存的时间 $smarty -> display('caching_conf.tpl'); ?>

文件三,模板文件:

{config_load file="smarty.conf"}
<html>
<head>
<title>{#title#}</title>
</head>
<body> {#content#} </body>
</html>

这样,title和content的地方就被换成“网站主页”和“一个网站的主体部分”。

如果{config_load file="smarty.conf" section="news"},

section表示读取哪部分的局部变量以供目前模板使用。

以上红色部分加载的是news部分的局部变量,title和content被换成新闻页面和新闻内容。

最新文章

  1. 安装生物信息学软件-bowtie2
  2. 移植u-boot-1.1.6之mtdparts分区
  3. 怎么做QQ、微信等消息气泡
  4. Codeforces 414C Mashmokh and Reverse Operation
  5. Session里的对象是不可靠的!
  6. You and your research
  7. 超轻量级高性能ORM数据访问组件Deft,比dapper快20%以上
  8. grep与正则表达式,grep、egrep和fgrep
  9. Tomcat8 + Redis实现session集中管理
  10. tomcat运行war包报错,找不到context-root文件
  11. 201521123104 《Java程序设计》 第12周学习总结
  12. dedecms首页调用软件下载地址
  13. Linux、docker、kubernetes、MySql、Shell、kafka、RabbitMQ运维快餐
  14. angular.js使用ui-router注入报错,这里是版本问题导致的
  15. Spark开发环境搭建(IDEA、Scala、SVN、SBT)
  16. mssql 数据库表行转列,列转行 比较经典
  17. MFC 中CString 格式16进制转int 十进制
  18. 理解交叉熵(cross_entropy)作为损失函数在神经网络中的作用
  19. Blazor
  20. 安装ubuntu gnome桌面

热门文章

  1. PHP中长连接的实现
  2. dede-搜索
  3. Margin的垂直外边距问题
  4. 捕获JSON 解析错误
  5. css3中的BFC,IFC,GFC和FFC(转载)
  6. sublime 安装 Terminal 使用 cmder
  7. 01_SpringMVC流程架构图
  8. 【制作镜像Win*】特殊配置
  9. 《C和指针》
  10. ajax详解,以及异步JSOP的实现