Or ecshop problems: how can iteration in smarty start from 2?

Source: Internet
Author: User
Or ecshop question: how can iteration in smarty start from 2? & lt ;! -- {Foreach & nbsp; from = product & nbsp; item = pro & nbsp; name = pro} -- & gt; // iteration & nbsp; the default value is from 1 {$ smarty. forea or ecshop: how can iteration in smarty start from 2?

// Iteration starts from 1 by default.
{$ Smarty. foreach. pro. iteration}

// What should I do if I want to start from 11?
{$ Smarty. foreach. pro. iteration + 10 ?}


Do not use this if to determine {if $ smarty. foreach. pro. iteration = 1} 2 {/if}

Can I ?
------ Solution --------------------
You can add a start
Modify the foreach processing method in includes \ cls_template.php and find
Function _ compile_foreach_start ($ tag_args)
Add
$ I = $ attrs ['start']? $ Attrs ['start']: 0; // by neo

Add $ I ++ to the following if
If (! Empty ($ name ))
{
$ Foreach_props = "\ $ this-> _ foreach ['$ name']";
$ Output. = "{$ foreach_props} = array ('total' => count (\ $ _ from), 'iteration' => 0, 'I' =>{$ I }); \ n ";
$ Output. = "if ({$ foreach_props} ['total']> 0): \ n ";
$ Output. = "foreach (\ $ _ from AS $ key_part $ item): \ n ";
$ Output. = "{$ foreach_props} ['iteration'] ++; \ n ";
$ Output. = "{$ foreach_props} ['I'] ++; \ n"; // by neo
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.