mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Improve cycle
Update docs
This commit is contained in:
@ -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
|
||||
*
|
||||
|
@ -202,6 +202,10 @@ class Template extends Render {
|
||||
}
|
||||
}
|
||||
|
||||
public function tmpVar() {
|
||||
return '$t'.($this->i++);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append plain text to template body
|
||||
*
|
||||
|
Reference in New Issue
Block a user