通过Smarty模板绘制td?

时间:2010-11-07 01:07:29

标签: php smarty

我有类别和潜艇,我想用td中的sub绘制每个类别。我写这个代码,但它用一个td中的sub绘制所有类别。问题是什么?谢谢

{section name=catsubs loop=$arrClientsCategorySub}
<td width="28" height="26" align="center" style="background-image:url(images/categorycolor.png); background-repeat:no-repeat; background-color:{$arrClientsCategorySub[catsubs].color}">
{section name=catsub2 loop=$arrClientsCategorySub[catsubs].arrsubCompanies}
<a id="ict-font-inner5sub" href="categoriescompanies.php?categoryid={$arrClientsCategorySub[catsubs].arrsubCompanies[catsub2].catsubid}">{$arrClientsCategorySub[catsubs].arrsubCompanies[catsub2].catsubnumber}</a>
{/section}
</td>
<td width="5"></td>
{/section}

1 个答案:

答案 0 :(得分:0)

我认为您的<td>代码需要更深入一个{section}来绕过每个子代理。试试这个:

{section name=catsubs loop=$arrClientsCategorySub} 
  {section name=catsub2 loop=$arrClientsCategorySub[catsubs].arrsubCompanies}
    <td width="28" height="26" align="center" style="background-image:url(images/categorycolor.png); background-repeat:no-repeat; background-color:{$arrClientsCategorySub[catsubs].color}">
      <a id="ict-font-inner5sub" href="categoriescompanies.php?categoryid={$arrClientsCategorySub[catsubs].arrsubCompanies[catsub2].catsubid}">{$arrClientsCategorySub[catsubs].arrsubCompanies[catsub2].catsubnumber}</a> 
    </td>
  {/section}
  <td width="5"></td> 
{/section} 

此外,如果为<td>分配了样式类而不是长样式标记中的所有代码,那么您的代码将更加高效和轻量级。