html里{$title}的$title的来源有三种
temp2.html
1.assign[之前用到的方法]
2.smarty系统保留变量,不用赋值,自动获取3.从配置文件读取的配置变量
详细请看注释
<?php
/*html里{$title}的$title的来源有三种
1.assign[之前用到的方法]
2.smarty系统保留变量,不用赋值,自动获取
3.从配置文件读取的配置变量*/
require('../../smarty3/libs/Smarty.class.php');
$smarty=new Smarty();
$smarty->template_dir='./temp';
$smarty->compile_dir='./comp';
/*2 smarty系统保留变量:get,post,cookie,session,server数组
常量 $smarty.const.常量名 */
/*一般过程
php:$smarty->assign('id',$_GET['id']);
html: {$id}
now: in html: {$smarty.get.id} */
/*3不从数据库读数据,就写在配置文件里
1创conf文件夹,2配置地址,3写配置文件,4 html加b 用法{$smarty.config.名} or {#名#}*/
$smarty->config_dir='./conf';
$smarty->display('temp2.html');
?>
temp2.html
{config_load file='var.conf'}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>temp2</title>
</head>
<body>
<h1>{$smarty.get.id}</h1>
<p>---smarty.get.id,在地址栏写?id=
</p>
<table>
<tr><td>内容</td><td>{$smarty.config.content}</td></tr>
<tr><td>电话</td><td>{#tel#}</td></tr>
</table>
</body>
</html>
content=hello
tel=123456
tel里数字不能太长,太长会溢出,和php设定有关
若一定要长可tel='1234567890' ,强行字符串就可以了