config_load的属性

     
属性类型是否必须缺省值描述
filestringYesn/a 待包含的配置文件的名称
sectionstringNon/a 配置文件中待加载部分的名称
scopestringnolocal 加载数据的作用域,取值必须为local, parent 或 global. local 说明该变量的作用域为当前模板. parent 说明该变量的作用域为当前模板和当前模板的父模板(调用当前模板的模板). global 说明该变量的作用域为所有模板.
globalbooleanNoNo 说明加载的变量是否全局可见,等同于 scope=parent. 注意: 当指定了 scope 属性时,可以设置该属性,但模板忽略该属性值而以 scope 属性为准。


if.conf

#全局变量
bgcolor = #00ffff
display = true            // 主要起限制作用

[mycolor]
bgcolor = #cccc00


[yourcolor]
bgcolor = #123456

if.html

<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>

if.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.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# }>        //如果display=true,则执行以下代码
<{ 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 }>                       //如果display不等于true ,则执行以下代码
没有显示
<{/if}>
</body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值