smarty模板中传值给php变量 从而实现不同的循环值

 <?php

 define("WOB","smarty/libs/");

 include(WOB."Smarty.class.php");

 $smarty = new Smarty;//设置各个目录的路径,这里是安装的重点

$smarty->template_dir ="smarty/templates/templates";

 $smarty->compile_dir ="smarty/templates/templates_c";

$smarty->config_dir = "smarty/templates/config";

$smarty->cache_dir ="smarty/templates/cache";

 $smarty->left_delimiter="<--{"; $smarty->right_delimiter="}-->";

 $smarty->caching = false;

 $foo = $smarty->get_template_vars('foo');

 $sql="select * from cct where id='".$foo."'";

$smarty->assign("name",$foo[0]);

 $smarty->assign("namer",$foo[1]);

$content=$smarty->fetch("2.tpl");

$title="./2.html";

 MfileText($title,$content);

 function MfileText($Mtitle,$Content) {

         if(!file_exists(dirname($Mtitle))) {

                if(!@mkdir(dirname($Mtitle),0777)) {

               die($Mtitle."false");

                }

    }

 if(!$tp=fopen($Mtitle,"w")) {

        echo "false"; return false;

     }

     if(!fwrite($tp,$Content)) {

 echo "file write false";

 fclose($tp); return false;

 } fclose($tp);

 chmod($Mtitle,0666);

 }

?>

2.tpl代码:

<--{assign var="foo" value="6"}--><--{$name}--><br /><--{$namer}-->

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值