ecshop foreach里增加start

<!--{foreach from=cattree item=cat name=cat0 start=10}-->
index:{$smarty.foreach.cat0.index}
<br />
iteration:{$smarty.foreach.cat0.iteration}
<br />
first:{$smarty.foreach.cat0.first}
<br />
last:{$smarty.foreach.cat0.last}
<br />
i:{$smarty.foreach.cat0.i}
<br />
<hr />
<!--{/foreach}-->

修改 includescls_template.php 里面的 foreach 处理方法,找到

function _compile_foreach_start($tag_args)

在里面的输出之前添加 2行,标注着 by neo 的那2行

$i = $attrs['start'] ? $attrs['start'] : 0;	//by neo
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
}
阅读剩余
THE END