从配置文件读取的变量
配置文件中的变量需要通过用两个"#"或者是smarty
的保留变量 $smarty.config来调用
例子:
a.conf 文件
bgcolor=#00cccc
display=true
[mycolor]
bgcolor=#96ffcc
[yourcolor]
bgcolor=#847591
if.tpl 文件
<{config_load file="a.conf" section="mycolor"}>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body bgcolor=<{#bgcolor#}>>
<{if #display#}>
<{if $dq=='left'}>
<div style="float:left">
<table border="1">
<tr>
<{section name=stuinfo loop=$text}>
<td><{$text[stuinfo]}></td>
<{/section}>
</tr>
</table>
</div>
<{elseif $dq=='right'}>
<div style="float:right">
<table border="1">
<tr>
<{section name=stuinfo loop=$text}>
<td><{$text[stuinfo]}></td>
<{/section}>
</tr>
</table>
</div>
<{else}>
<center><div>
<table border="1">
<tr>
<{section name=stuinfo loop=$text}>
<td><{$text[stuinfo]}></td>
<{/section}>
</tr>
</table>
</div></center>
<{/if}>
<{else}>显示功能没有打开,请打开配置文件,将
display=false改为display=true
<{/if}>
</body>
</html>
array_from.html 文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="array_from.php" method="post">
输入学号查询:
<input type="text" name="text" /><br/>
选择显示方式:
<input type="radio" value="left" name="ss" />left
<input type="radio" value="center" name="ss"
/>center
<input type="radio" value="right" name="ss"
/>right<br />
<input type="submit" value="确定" />
</form>
</body>
</html>
array_from.php 文件
<?php
include("libs/Smarty.class.php");
$link = mysql_connect('localhost','root','123');
mysql_select_db('xf',$link);
mysql_query("set names utf8");
$sql = "select * from stuinfo where stu_id like
'".$_POST["text"]."'";
$result=mysql_query($sql,$link);
$row=mysql_fetch_row($result);
$smarty=new Smarty();
$smarty->config_dir="demo/config";
$smarty->reInitSmarty
("demo/templates","demo/templates_c");
$smarty->assign("text",$row);
$smarty->assign("dq",$_POST["ss"]);
$smarty->display("if.tpl");