【问题标题】:Swap Content Layout in a Loop Using Smarty使用 Smarty 循环交换内容布局
【发布时间】:2016-04-12 13:39:07
【问题描述】:

我正在使用使用 smarty 的 CMSMS。我需要以奇数/偶数顺序显示新闻模块的内容。我试过使用 {cycle} 和 {section} 但我不是程序员,所以我只是在这里猜测。 Layout Sample

每个布局的示例代码如下所示:

<!-- Layout A -->
<div class="row">
        <div class="col-lg-8 col-md-8 col-sm-8 text-center">
            <div class="image">
                Image
            </div>
        </div>
        <div class="col-lg-4 col-md-4 col-sm-4 text-center">
            <div class="text">
                Text Content
            </div>
        </div>
    </div>
<!-- Layout B -->
    <div class="row">
        <div class="col-lg-4 col-md-4 col-sm-4 text-center">
            <div class="text">
                Text Content
            </div>
        </div>
        <div class="col-lg-8 col-md-8 col-sm-8 text-center">
            <div class="image">
                Image
            </div>
        </div>
    </div>

我有几条新闻,它们应该像这样呈现:

  1. 布局 A
  2. 布局 B
  3. 布局 A
  4. 布局 B
  5. 等等……

这可以使用 smarty 吗?

提前感谢您对此提供的任何帮助。

【问题讨论】:

    标签: php layout smarty cmsmadesimple


    【解决方案1】:

    如果您的 CMSms 版本使用 Smarty 3,请使用

         {foreach $myNames as $name}
           {if $name@iteration is div by 2}
             <!-- Layout B -->
           {else}
             <!__ Layout A -->
           {/if}
         {/foreach}
    

    【讨论】:

    • 感谢您的回答。您的解决方案有点工作,因为它只呈现“布局 A”。我看到的是获取内容所需的 {foreach} 看起来像这样 {foreach from=$items item=entry}。所以我假设 {if $name@iteration is div by 2} 应该不同。我对吗? :D
    • 是的,这是一个通用的东西。将 $name 更改为 $entry 并将 $myNames 更改为 items
    猜你喜欢
    • 1970-01-01
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    • 2011-07-27
    • 1970-01-01
    • 2010-09-13
    相关资源
    最近更新 更多