【问题标题】:3 Column Layout - Looping through Dynamic Data3 列布局 - 循环动态数据
【发布时间】:2010-09-05 13:50:52
【问题描述】:

我的页面的一列(侧栏)上的li's 中包含类别列表。我现在希望它在几列中跨越页面的整个宽度。我总是希望 3 或 4 列适合页面。这是生成一列的代码。

        <div id="sidebar">
            <ul>
                {insert name=get_audio_categories assign=listcats}
                {section name=o loop=$listcats}
                <li><a href="{$baseurl}/z/{$listcats[o].CATID}/1/{$listcats[o].name}">{$listcats[o].name|stripslashes}</a> ({insert name=audio_categories_count value=a assign=atotal catid=$listcats[o].CATID}{$atotal} {$lang875}) </li>
                {/section}
            </ul>
        </div>

我之前问过一个类似的问题,但这是使用纯 php 和表格布局。我似乎无法在下面提取此逻辑并应用于上述 smarty tpl 文件:

$nbCols = 4;
$nbRows = count($indexes)/$nbCols;
for($row=0; $row<$nbRows; $row++) {
    echo "<tr>";
    for($i=0; $i<$nbCols; $i++) {
        $index = $indexes[$row + ($i*$nbRows)];
        echo "<td>$index</td><td><input id='$index' name='$index' type='checkbox' /></td>";
    }
    echo "</tr>";

我可以得到类别的总数。

感谢大家的帮助。

【问题讨论】:

    标签: php layout smarty template-engine


    【解决方案1】:

    利用Smarty的foreach内置函数来显示列。

    可以在这里找到示例http://www.smarty.net/manual/en/language.function.foreach.php

    您的 PHP 代码所需要的只是一个包含您想要显示的信息的数组。这很像您使用section 函数的方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-12
      • 1970-01-01
      • 2022-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多