我想使用section在smarty tpl中创建一个变量。我在类中使用for循环分配了变量。我的代码是:
for($i=1;$i<=$_REQUEST['parcel_quantity'];$i++)
{
${"grith_".$i}=$_REQUEST['parcel_grith_'.$i];
${"width_".$i}=$_REQUEST['parcel_width_'.$i];
${"height_".$i}=$_REQUEST['parcel_height_'.$i];
${"weight_".$i}=$_REQUEST['parcel_weight_'.$i];
${"volumetric_weight".$i}=(${"grith_".$i}*${"width".$i}*${"height_".$i})/4000;
$objSmarty->assign("volumetric_weight".$i,${"volumetric_weight".$i});
$objSmarty->assign("select_l".$i,${"grith_".$i});
$objSmarty->assign("select_w".$i,${"width_".$i});
$objSmarty->assign("select_h".$i,${"height_".$i});
$objSmarty->assign("select_weight".$i,${"weight_".$i});
}
现在我想在tpl中使用这些指定的值:
{section name=data start=0 loop=$parcel_quantity}`
<li><a ><strong>Dimentions :-</strong> {$select_h}{$smarty.section.data.index+1}{$unit} X {$select_w}{$smarty.section.data.index+1}{$unit} X {$select_l}{$unit}</a></li>
<li><a ><strong>Volumetric Weight :-</strong> {$volumetric_weight}{$smarty.section.data.index+1}Kg</a></li>
{/section}
答案 0 :(得分:0)
尝试这样做会起作用:
tpl:
{section name=data start=0 loop=$parcel_quantity}
{$parcel_quantity[data].value}
{/section}
这里,{$parcel_quantity[data].value}
是从该部分检索的值。您必须将field name
替换为value
。
答案 1 :(得分:0)
最后我用另一种方法得到了它。我将所有值都放在一个变量中并分配它并在tpl中用作smarty变量。
for($i=1;$i<=$_REQUEST['parcel_quantity'];$i++)
{
${"grith_".$i}=$_REQUEST['parcel_girth_'.$i];
${"width_".$i}=$_REQUEST['parcel_width_'.$i];
${"height_".$i}=$_REQUEST['parcel_height_'.$i];
${"weight_".$i}=$_REQUEST['parcel_weight_'.$i];
${"volumetric_weight".$i}= ($_REQUEST['parcel_girth_'.$i]*$_REQUEST['parcel_width_'.$i]*$_REQUEST['parcel_height_'.$i])/4000 ;
if(${"weight_".$i}>${"volumetric_weight".$i})
${"weight_main_".$i}=${"weight_".$i};
else
${"weight_main_".$i}=${"volumetric_weight".$i};
$total_weight+= ${"weight_main_".$i};
// Put all values in variable with design
$veiw_in_right.='
<li><strong>Parcel Detail:'.$i.'</strong></li><li><a ><strong>Dimentions :-</strong> '.${"height_".$i}.$unit.' X '.${"width_".$i}.$unit.' X '.${"grith_".$i}.$unit.'</a></li>
<li><a ><strong>Volumetric Weight :-</strong> '.${"volumetric_weight".$i}.'Kg</a></li>
<li><a ><strong>Weight:-</strong> '.${"weight_".$i}.'Kg</a><hr></li>';
$objSmarty->assign("veiw_in_right",$veiw_in_right);
}
在Tpl中只需输入变量:
<li><a ><strong>No of Pieces :-</strong> {$parcel_quantity}</a><hr /></li>
{$veiw_in_right}
<li><a ><strong>Total Weight :-</strong> {$total_weight}Kg</a></li>