SMARTY HELP: how to print a number for -foreach-

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gleem
    Confirmed User
    • Jun 2001
    • 5593

    #1

    SMARTY HELP: how to print a number for -foreach-

    If am doing a "foreach" and this is the foreach statement... how do I get smarty to out put a count number for each "foreach" it outputs?

    here's the smarty foreach statement I'm using in my CARMA template:

    PHP Code:
    {foreach from=$carma_comments item=comments} 
    
    Basically just want to show the comment number on a particular gallery and since it stores the comment ID as overall sitewide comment there's no comment number for that gallery in the array.




    Contact me: \\// E: webmaster /at/ unprofessional.com
  • fris
    Too lazy to set a custom title
    • Aug 2002
    • 55679

    #2
    smarty has a counter function

    http://www.smarty.net/docsv2/en/lang...nction.counter
    Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

    Comment

    • gleem
      Confirmed User
      • Jun 2001
      • 5593

      #3
      Originally posted by fris
      ahh, I knew I was missing something, thanx




      Contact me: \\// E: webmaster /at/ unprofessional.com

      Comment

      • JayS
        Confirmed User
        • Oct 2007
        • 138

        #4
        Originally posted by gleem
        ahh, I knew I was missing something, thanx
        If you just need the number of the iteration you can use something like this:

        PHP Code:
        {foreach from=$carma_comments item=comments name=bla}  
            Comment #{$smarty.foreach.bla.iteration}
        {/foreach} 
        
        More info here: http://www.smarty.net/docsv2/en/lang...nction.foreach

        Comment

        • Diomed
          Converting like it's 1999
          • Jan 2009
          • 6167

          #5
          Thank god I'm on the advertising side of things.
          10 years of experience in:

          CHAT SALES - PAID TRAFFIC - CONVERSION - CREATIVES - CONSULTATION

          Comment

          • Fucksakes
            Shit... Fuck! What the Hell?
            • Dec 2003
            • 7567

            #6
            Originally posted by Diomed
            Thank god I'm on the advertising side of things.
            always good to know more ;)

            Comment

            • gleem
              Confirmed User
              • Jun 2001
              • 5593

              #7
              Originally posted by Fucksakes
              always good to know more ;)
              No doubt, I do design, marketing, affiliate repping, write articles, html css & push php & smarty code around... just enough to get by at least.

              Some people do 1 thing great, I do many things good, and a few things above or below average.




              Contact me: \\// E: webmaster /at/ unprofessional.com

              Comment

              Working...