protected function _parseLoop($key = null)
{
$replace = array();
foreach ($this->_doSearch('loop', $key) as $val) {
$divider = null;
// See if we have a divider.
if (preg_match("/<divider:" . $val[1] . ">(.*)<\\/divider:" . $val[1] . ">/sU", $this->_template, $m)) {
$divider = $m[1];
$replace[$m[0]] = '';
}
if (!isset($this->_foreachMap[$val[1]])) {
$this->_foreachMap[$val[1]] = ++$this->_foreachVar;
}
$varId = $this->_foreachMap[$val[1]];
$var = $this->_generatePHPVar('arrays', $val[1]);
$replace[$val[0]] = '<?php ' . ($divider ? '$i' . $varId . ' = count(' . $var . '); ' : '') . 'foreach (' . $this->_generatePHPVar('arrays', $val[1]) . ' as $k' . $varId . ' => $v' . $varId . '): ?>';
$replace[$val[2]] = '<?php ' . ($divider ? 'if (--$i' . $varId . ' != 0) { echo \'' . $divider . '\'; }; ' : '') . 'endforeach; ?>';
// Parse ifs.
$this->_parseIf($val[1]);
// Parse interior loops.
$this->_parseLoop($val[1]);
// Replace scalars.
$this->_parseTags($val[1]);
}
$this->_doReplace($replace);
}