我可以在PHP中使用HTML_Template_Sigma在变量中循环吗?

时间:2015-05-22 04:07:31

标签: php html pear

我必须使用HTML_Template_Sigma PEAR模块在PHP上进行分配,它基本上包装了网站的所有HTML以使用它制作模板,而不是一遍又一遍地粘贴相同的HTML。问题是所有内容都是使用变量添加的,在某些时候我必须遍历其中一个字符串变量(里面有一个表)内的数组。所以我检查了文档不是很丰富,它确实有一些循环实现,但面向出版物,我不知道如何使用它来解决我的问题。

http://www.pixel2life.com/publish/tutorials/13/pear_module_html_template_sigma/

http://pear.php.net/manual/en/package.html.html-template-sigma.intro-syntax.php

他们展示的内容与此不完全相同。

  foreach ($data as $result) {

$plantilla->setCurrentBlock('table_row');
$plantilla->setVariable(array(
    'date'  => $result[0],
    'epicentre' => $result[1],
    'region' => $result[2],
    'richter' => $result[3],
    'mercalli' => $result[4]

));
$plantilla->parseCurrentBlock('table_row');
}

这是我的变量:

content = '
   <table>
                      <thead>
        <tr>
            <th>Date</th>
            <th>Epicentre</th>
            <th>Region</th>
            <th>Mw Richter</th>
            <th>Mercalli</th>
        </tr>
    </thead>
    <tbody>
<!-- BEGIN table_row -->
    <tr>
<td>{date}</td>
<td>{epicentre}</td>
<td>{region}</td>
<td>{richter}</td>
<td>{mercalli}</td>
</tr>
<!-- END table_row -->
   </tbody>
                </table>';  

我的数组包含5列数据。我试过但无济于事。

提前致谢!

0 个答案:

没有答案