Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7891815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:42:49+00:00 2026-06-03T06:42:49+00:00

I have a foreach loop code in a tpl file like this: [{foreach from=$oView->getArticleList()

  • 0

I have a foreach loop code in a tpl file like this:

[{foreach from=$oView->getArticleList() item=actionproduct name=test_articleList}]
[{include file="inc/product_alt.tpl"  product=$actionproduct testid="action_"|cat:$actionproduct->oxarticles__oxid->value test_Cntr=$smarty.foreach.test_articleList.iteration}]
[{/foreach}]

the included file product_alt.tpl in the foreach loop contains a simple div container and get displayed for each product. Now i am looking for a solutions to add to every second div container a extra class.

I google a bit and found out (i think so) that I must work with even and odd. But i stucked how to apply this exactly to the foreach loop with the goal that every secod div container get an extra class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:42:50+00:00Added an answer on June 3, 2026 at 6:42 am

    You are looking for cycle. What you can do for instance is assign an extra $class variable in your include statement, that gets changed by the assign, like so:

     {cycle values='yourClass1,youClass2' assign='class'} 
    

    That’s probably where your odd/even thought comes from: the manual says

     {cycle values='odd,even' assign='class'} 
    

    But those are just values. Anyeay, your variable ‘class’ now has alternating “yourClass1” and “yourClass2” (or odd/even) as content. If you assign this to your include, and then add something like

    <div class="{$class}">
    

    You get alternating classes. One of them is the one you want. the other can be empty..

    check out the cycle manual: http://www.smarty.net/docsv2/en/language.function.cycle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to create a list from a foreach loop from membershipuser
I have seen in cakephp that foreach loop is used like this foreach($tags as
I have a foreach loop like below foreach (XYZ split in this.splits ) {
I have a foreach loop like this $sn_count = 1; $html = ''; foreach($points
I have the following tpl codes: {foreach from=$data.reviews item=item} {$item.user_name},{$item.datestamp} {/foreach} I'm creating a
The following code returns the error from the For Each loop. I have similar
I have a function which performs a foreach loop on an array from a
The question is simple. I have a foreach loop in my code: foreach($array as
Let's say I have this foreach loop: foreach ($lists as $list) { if (next
I have some code that creates objects in a foreach loop. So: private IEnumerable<StrongTypeResult>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.