dongtong2021 2016-11-19 16: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 14: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}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥20 DNS服务器所在的国家不同与你的IP地址所在国家
  • ¥15 查询优化:A表100000行,B表2000 行,内存页大小只有20页,运行时3页,设计两个表等值连接的最简单的算法
  • ¥15 led数码显示控制(标签-流程图)
  • ¥20 为什么在复位后出现错误帧
  • ¥15 结果有了,想问一下这个具体怎么输入
  • ¥15 怎么修改鸿蒙app的UI及功能设计
  • ¥15 帮我利用jupyter 运行一个正确的代码
  • ¥15 sqlite加密问题咨询
  • ¥15 appdesigner接收不到udp组播的数据
  • ¥15 verilog 非阻塞赋值下的移位拼接错误
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部