还是ecshop问题:smarty里的 iteration 如何才能从2开始

WBOY
Release: 2016-06-23 14:01:37
Original
836 people have browsed it


//iteration 默认是从1开始
{$smarty.foreach.pro.iteration}

//如果我想从11开始应该怎么写?
{$smarty.foreach.pro.iteration + 10?}


不要用这样的 if 判断的 {if $smarty.foreach.pro.iteration = 1}2{/if}

能否在   ?


回复讨论(解决方案)

可以加个start 
修改 includes\cls_template.php 里面的 foreach 处理方法,找到 
function _compile_foreach_start($tag_args)
在里面的输出之前添加一个
$i = $attrs['start'] ? $attrs['start'] : 0; //by neo

下面的if里面加入 $i++
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
}

start=2 试试

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template