foreach循环中的Smarty备用视图元素

时间:2019-06-28 06:27:16

标签: smarty smarty3

我正在尝试找到一种通过以下方式循环浏览内循环视图项的方法:

第一:

<div class="col-sm-6">
    <h3 class="padding-bot-20">{$row->service}</h3>{$row->content}
</div>
<div class="col-sm-6">
    <img class="img-responsive" src="{$this->images->frontend_check_image($row->main_image)}" alt="Service">
</div>

第二:

<div class="col-sm-6">
    <img class="img-responsive" src="{$this->images->frontend_check_image($row->main_image)}" alt="Service">
</div>
<div class="col-sm-6">
    <h3 class="padding-bot-20">{$row->service}</h3>{$row->content}
</div>

以此类推...因此演示文稿是内容/图像,图像/内容,内容/图像等。

这是主要代码:

    <div class="container">
        {if count($row_services) == 0}
            No services published.
        {else}
            {assign var=i value=0}
            {foreach from=$row_services item=row}
                <div class="row scroll-animated-from-bottom {if $i > 0}padding-top-50{/if}" id="service-data-1">
                    <div class="col-sm-6">
                        <h3 class="padding-bot-20">{$row->service}</h3>{$row->content}
                    </div>
                    <div class="col-sm-6">
                        <img class="img-responsive" src="{$this->images->frontend_check_image($row->main_image)}" alt="Service">
                    </div>
                </div>
            {capture assign=i}{$i+1}{/capture}
            {/foreach}
        {/if}
    </div>

我知道如何做到这一点是php,但是我不确定如何以聪明的方式做到这一点。我试图避免出现任何子视图。

1 个答案:

答案 0 :(得分:0)

这是我能想到的最好的方法。如果有人有更好的解决方案,请随时分享:

<div class="List">
  <ul>
    <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
    </li>
    <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean </li>
    <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
    </li>
    <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
    </li>
    <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean </li>
    <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
    </li>
    <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
    </li>


  </ul>
</div>