mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add {unset …} (#29)
This commit is contained in:
parent
050523f249
commit
8030c12923
@ -228,6 +228,10 @@ class Fenom {
|
||||
'type' => self::BLOCK_COMPILER,
|
||||
'open' => 'Fenom\Compiler::autoescapeOpen',
|
||||
'close' => 'Fenom\Compiler::autoescapeClose'
|
||||
),
|
||||
'unset' => array(
|
||||
'type' => self::INLINE_COMPILER,
|
||||
'parser' => 'Fenom\Compiler::tagUnset'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -914,4 +914,23 @@ class Compiler {
|
||||
public static function autoescapeClose(Tokenizer $tokens, Scope $scope) {
|
||||
$scope->tpl->escape = $scope["escape"];
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset present variables
|
||||
*
|
||||
* @param Tokenizer $tokens
|
||||
* @param Template $tpl
|
||||
* @return string
|
||||
* @throws InvalidUsageException
|
||||
*/
|
||||
public static function tagUnset(Tokenizer $tokens, Template $tpl) {
|
||||
$vars = array();
|
||||
while($tokens->valid()) {
|
||||
$vars[] = $tpl->parseVar($tokens);
|
||||
}
|
||||
if(!$vars) {
|
||||
throw new InvalidUsageException("Unset must accept variable(s)");
|
||||
}
|
||||
return 'unset('.implode(', ', $vars).')';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user