dongtong2021 2016-11-20 00:18 采纳率: 0%
浏览 67
已采纳

无法在Smarty foreach中复制HTML代码

I have a block of code I'm trying to replicate using a foreach, but I can't get around on how to do this the code is as follows:

     <div class="panel panel-default">
        <div class="panel-heading">
          <h4 class="panel-title">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">Content</a>
          </h4>
        </div>
        <div id="collapseOne" class="panel-collapse collapse in">
          <div class="panel-body">
            <table class="table">
              <tr>
                <td>
                  <span class="glyphicon glyphicon-pencil text-primary"></span><a href="">Articles</a>
                </td>
              </tr>
              <tr>
                <td>
                  <span class="glyphicon glyphicon-flash text-success"></span><a href="#">News</a>
                </td>
              </tr>
              <tr>
                <td>
                  <span class="glyphicon glyphicon-file text-info"></span><a href="#">Newsletters</a>
                </td>
              </tr>
              <tr>
                <td>
                  <span class="glyphicon glyphicon-comment text-success"></span><a href="#">Comments</a>
                  <span class="badge">42</span>
                </td>
              </tr>
            </table>
          </div>
        </div>
      </div>

This is part of a collapsible sidebar, and ideally the EG and the AG have a section to themselves

This is the array I'm trying to display on this block

    $smarty -> assign('produtosGC1',
    array('EG' => array('Tipo ST','Tipo LP','Tipo SG','Hollowbody'),
    'AG' => array('Clássicas','Aço')
    ));

This is my attempt, almost there:

      <div class="panel panel-default">

        {foreach $produtosGC1 as $produto}
        <div class="panel-heading">
          <h4 class="panel-title">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">{$produto@key}</a>
          </h4>
        </div>
        <div id="collapseOne" class="panel-collapse collapse in"> 
          <div class="panel-body">
            <table class="table">
             {foreach $produto as $item}
              <tr>
                <td>
                  <a href="">{$item}</a>
                </td>
              </tr>
             {/foreach}
            </table>
          </div>
        </div>
        {/foreach}
      </ul>
    </div>

The thing is, the second title (the AG) does not link properly with its sub-categories and doesn't collapse correctly

Edit:changed the question title because it wasn't correct

  • 写回答

1条回答 默认 最新

  • doutucui0133 2016-11-23 22:57
    关注

    After tinkering and thanks to @Darren H's tip I got it working and it's as follows:

    {foreach $produtos as $produto}
        <div class="panel-heading">
          <h4 class="panel-title">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapse{$produto@index}">{$produto@key}</a>
          </h4>
        </div>
        <div id="collapse{$produto@index}" class="panel-collapse collapse in">
          <div class="panel-body">
            <table class="table sidebar">
              {foreach $produto as $item}
              <tr>
                <td>
                  <a href="{$item}">{$item@key}</a>
                </td>
              </tr>
              {/foreach}
            </table>
          </div>
        </div>
        {/foreach}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计