无法在Smarty foreach

时间:2016-11-20 00:18:43

标签: php html smarty3

我有一段代码,我正在尝试使用foreach进行复制,但我无法解决如何执行此操作的代码如下:

     <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>

这是可折叠侧边栏的一部分,理想情况下,EG和AG有自己的部分

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')
    ));

这是我的尝试,几乎就在那里:

      <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>

问题是,第二个标题(AG)没有与其子类别正确链接,也没有正确折叠

编辑:更改了问题标题,因为它不正确

1 个答案:

答案 0 :(得分:0)

经过修修补补并感谢@Darren H的小费,我得到了它的工作,其内容如下:

Error