夺命雷公狗---Smarty NO:22 常量—变量

1、常量

在smarty模版引擎里面是有自定义了很多常量的,如SMARTY_DIR  等等…….

2、变量

  • $template_dir:模板目录
  • $compile_dir:编译目录
  • $config_dir:配置文件目录
  • $cache_dir:缓存文件目录
  • $left_delimiter:左分隔符
  • $right_delimiter:右分隔符
  • $caching:缓存开关
  • $cache_lifetime:缓存生命周期
  • $debugging:boolean类型值,true开启调试,功能与{debug}

在Smarty2.0版本中,debugging只能调试php分配到模板中的变量,而无法调试页面中直接定义的变量,在Smarty3.0,两者皆可以进行调试

代码如下:

demo7.php 代码示例

<?php
require “smarty/Smarty.class.php”;
$smarty = new Smarty();
$smarty ->debugging = true;
$title = “hello”;
$smarty -> assign(‘title’,$title);
$smarty -> display(‘demo7.html’);

demo7.html代码示例:

<!DOCTYPE html>
<html>
<head>
<meta charset=’utf-8′>
<title></title>
<script src=”jquery.js”></script>
</head>
<body>
{$title}
</body>
</html>

$php_handling(参数):是否可以在模板页面中直接使用php代码

Smarty::PHP_PASSTHRU – 原样输出这些代码,默认的

Smarty::PHP_QUOTE – 把这些代码转换成HTML实体显示

Smarty::PHP_REMOVE – 清除这些代码

Smarty::PHP_ALLOW – 作为PHP代码来执行

此属性在3.0中已废弃。

原文地址:https://www.cnblogs.com/leigood/p/5033455.html