if.conf
#全局变量
bgcolor = #00ffff
display = true
[mycolor]
bgcolor = #cccc00
[yourcolor]
bgcolor = #123456
if_else.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>if_else</title> </head> <body> <form action="if_else.php" method="post"> <input type="text" name="text" /> <input type="radio" name='dq' value="left" />left <input type="radio" name='dq' value="right" />right <input type="radio" name='dq' value="center" />center<br /> <input type="submit" value="提交" />
</form> </body> </html>
if_else.php
<?php
include 'libs/Smarty.class.php';
$link = mysql_connect('localhost','root','123') or die('数据库连接失败');
mysql_select_db('ecshop_test',$link);
mysql_query("set names utf8");
$sql = mysql_query("select * from brand where id like '".$_POST['text']."'");
$result = mysql_fetch_row($sql);
$smarty = new Smarty();
$smarty->template_dir="demo/templates";
$smarty->compile_dir="demo/templates_c";
$smarty->config_dir="demo/config";
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
$smarty->assign('text',$result);
$smarty->assign('dq',$_POST['dq']);
$smarty->display('if_else.tpl');
if_else.tpl
<{config_load file='if.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>if_else</title>
</head>
<body bgcolor=<{ #bgcolor# }>>
<{ if #display# }>
<{ if $dq=='left'}>
<div style=" float:left;">
<table>
<tr>
<{ foreach from=$text item=value }>
<td><{ $value }></td>
<{ /foreach }>
</tr>
</table>
</div>
<{ elseif $dq=='right'}>
<div style=" float:right;">
<table>
<tr>
<{ foreach from=$text item=value }>
<td><{ $value }></td>
<{ /foreach }>
</tr>
</table>
</div>
<{else}>
<center><div>
<table>
<tr>
<{ foreach from=$text item=value }>
<td><{ $value }></td>
<{ /foreach }>
</tr>
</table>
</div></center>
<{/if}>
<{ else }>
没有显示
<{/if}>
</body>
</html>