Back to Top

How to use counter into foreach loop Smarty?

To use counter in Smarty loop

Smarty is one of PHP template Engine which is used to templating purpose and Today in this quick article, I am going to explain how to setup counter into smarty in any loop like for,foreach or while.

However, Before few days I want to use counter inside a foreach loop that accept a start value and increase by one until the loop continues.

so Let’s understand by code:

First of all take one variable and assign start value

{counter assign=i start=0 print=false}

{foreach from=datas item=data}
	{counter} // this will increase value something like i++
{/foreach}

You can check value by printing variable {i} in loop.

To print array into smarty, you can use below code:


{$var|@debug_print_var}

Read: To add Signup Bonus in X-Cart

That’s it.I hope this tutorial will be helpful to you.

Don’t hesitate to use this code in your projects and post your comments if you need help. As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

PHP 7 new Features at a Glance

Posted on 3 years ago

Bhumi

HTML5 Geolocation API with Example

Posted on 1 year ago

Bhumi

Angularjs 2 Tutorial for Beginners

Posted on 2 years ago

Bhumi

The Readers’ Poll – June 2013

Posted on 5 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 3 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 4 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 4 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 5 years ago

Bhumi