简体   繁体   中英

Swap Content Layout in a Loop Using Smarty

I'm using CMSMS which uses smarty. I need to show the content of the News Module in an odd/even order. I've tried using {cycle} and {section} but I'm not a programmer so I'm just guessing here. Layout Sample

The sample code for each layout is something like this:

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

I have several news and they should be presented like this:

  1. Layout A
  2. Layout B
  3. Layout A
  4. Layout B
  5. And so on...

Is this possible using smarty?

Thanks in advance for any help on this.

If your CMSms version uses Smarty 3 use

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM