Improve cycle

Update docs
This commit is contained in:
bzick
2013-03-15 00:57:28 +04:00
parent 97e01e7f79
commit d4d7b7d07b
10 changed files with 60 additions and 20 deletions

View File

@ -695,10 +695,15 @@ class Compiler {
return __CLASS__.'::cycle((array)'.$exp.', '.$p["index"].');';
}
} else {
return __CLASS__.'::cycle((array)'.$exp.', isset($i) ? $i++ : ($i = 0) );';
$var = $tpl->tmpVar();
return "is_array($exp) ? ".__CLASS__.'::cycle('.$exp.", isset($var) ? $var++ : ($var = 0) ) : $exp";
}
}
public static function cycle($vals, $index) {
return $vals[$index % count($vals)];
}
/**
* Import macros from templates
*

View File

@ -202,6 +202,10 @@ class Template extends Render {
}
}
public function tmpVar() {
return '$t'.($this->i++);
}
/**
* Append plain text to template body
*