smarty怎么传值?

下面是我现在的代码:


index.tpl

{section name=arr loop=$rst max=2 start=0}
          
           {if $smarty.section.arr.index<2 }
           {* <?php for($i=0;$i<2;$i++){
	       $row=mysql_fetch_array($_result);
	       list(  $year,$month ,  $day  ) = preg_split  ( '[/.-]' , $news_date );*}
	   {*注释是原来的php代码*}
		   

		 
            <div class="n1">
                <div class="top_lefr">
                    <div class="day">{$day}</div>
                    <div class="year_month">{$year}{$month}</div>
                </div>
                <div class="top_right"><a href="new_con.php?&id={$rst[arr].news_id}&ntr={$rst[arr].news_type} " title="{$rst[arr].news_title|truncate:"32":"...":"true"}">{$rst[arr].news_title|truncate:"32":"...":"true"}</a></div>
                <div class="img"><a href="new_con.php?&id= {$rst[arr].news_id} &ntr={$rst[arr].news_type} "><img src="{$rst[arr].news_img}" width="1920" height="1200" /></a></div>
            </div>
            
           
           {/if} 
      		{/section}
            {* <?php }?> *}


index.php

<?php
require_once('include.php');

$sql="select * from tb_news where news_type='4' order by news_date DESC";
 
		
$rst = $admindb->ExecSQL($sql,$conn);

$rst_news_img=$rst[0]["news_img"];
for($i=0;$i<2;$i++){
$news_date=$rst[$i]["news_date"];
}
list(  $year, $month, $day  ) = preg_split  ( '[/.-]' , $news_date );

//$htgl=$_GET["htgl"];
$smarty->assign('rst',$rst);
$smarty->assign('rst_news_img',$rst_news_img);
$smarty->assign('year',$year);
$smarty->assign('month',$month);
$smarty->assign('day',$day);	
$smarty->display('index.tpl');

?>

像我这样做只能传固定的三个值($year, $month, $day ),

由于不能把逻辑控制部分放在tpl,但是不放在那里循环,得到的又只能是固定的值,根本不能对应起来。


怎么才能传对应的值?

错过了年华
浏览 2263回答 2
2回答

错过了年华

或者说smarty分割字符串的函数是什么?
打开App,查看更多内容
随时随地看视频慕课网APP