mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Improve #41
This commit is contained in:
parent
982b284f60
commit
25975a6782
@ -1,11 +1,11 @@
|
|||||||
Syntax [RU]
|
Syntax [RU]
|
||||||
===========
|
===========
|
||||||
|
|
||||||
Fenom have [Smarty](http://www.smarty.net/) like syntax.
|
Fenom implement [Smarty](http://www.smarty.net/) syntax with some improvements
|
||||||
|
|
||||||
## Variable
|
## Variable
|
||||||
|
|
||||||
### Get/print value
|
### Use variables
|
||||||
|
|
||||||
```smarty
|
```smarty
|
||||||
{$foo}
|
{$foo}
|
||||||
@ -20,7 +20,31 @@ Fenom have [Smarty](http://www.smarty.net/) like syntax.
|
|||||||
{$foo.$bar}
|
{$foo.$bar}
|
||||||
{$foo[$bar]}
|
{$foo[$bar]}
|
||||||
{$foo->bar}
|
{$foo->bar}
|
||||||
{$foo->bar()}
|
{$foo->bar.buz}
|
||||||
|
```
|
||||||
|
|
||||||
|
### System variable
|
||||||
|
|
||||||
|
Unnamed system variable starts with `$.` and allow access to global variables and system info:
|
||||||
|
|
||||||
|
* `$.get` is `$_GET`.
|
||||||
|
* `$.post` is `$_POST`.
|
||||||
|
* `$.cookie` is `$_COOKIE`.
|
||||||
|
* `$.session` is `$_SESSION`.
|
||||||
|
* `$.globals` is `$GLOBALS`.
|
||||||
|
* `$.request` is `$_REQUEST`.
|
||||||
|
* `$.files` is `$_FILES`.
|
||||||
|
* `$.server` is `$_SERVER`.
|
||||||
|
* `$.env` is `$_ENV`.
|
||||||
|
* `$.tpl.name` returns current template name.
|
||||||
|
* `$.tpl.schema` returns current schema of the template.
|
||||||
|
* `$.version` returns version of the Fenom.
|
||||||
|
* `$.const` paste constant.
|
||||||
|
|
||||||
|
```smarty
|
||||||
|
{if $.get.debug? && $.const.DEBUG}
|
||||||
|
...
|
||||||
|
{/if}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Multidimensional value support
|
### Multidimensional value support
|
||||||
|
@ -33,14 +33,6 @@ class Compiler
|
|||||||
public static function tagInclude(Tokenizer $tokens, Template $tpl)
|
public static function tagInclude(Tokenizer $tokens, Template $tpl)
|
||||||
{
|
{
|
||||||
$name = false;
|
$name = false;
|
||||||
// if($tokens->is('[')) {
|
|
||||||
// $tokens->next();
|
|
||||||
// if(!$name && $tokens->is(T_CONSTANT_ENCAPSED_STRING)) {
|
|
||||||
// if($tpl->getStorage()->templateExists($_name = substr($tokens->getAndNext(), 1, -1))) {
|
|
||||||
// $name = $_name;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
$cname = $tpl->parsePlainArg($tokens, $name);
|
$cname = $tpl->parsePlainArg($tokens, $name);
|
||||||
$p = $tpl->parseParams($tokens);
|
$p = $tpl->parseParams($tokens);
|
||||||
if ($p) { // if we have additionally variables
|
if ($p) { // if we have additionally variables
|
||||||
@ -706,7 +698,7 @@ class Compiler
|
|||||||
*/
|
*/
|
||||||
public static function varOpen(Tokenizer $tokens, Scope $scope)
|
public static function varOpen(Tokenizer $tokens, Scope $scope)
|
||||||
{
|
{
|
||||||
$var = $scope->tpl->parseVariable($tokens, Template::DENY_MODS);
|
$var = $scope->tpl->parseVar($tokens);
|
||||||
if ($tokens->is('=')) { // inline tag {var ...}
|
if ($tokens->is('=')) { // inline tag {var ...}
|
||||||
$scope->is_closed = true;
|
$scope->is_closed = true;
|
||||||
$tokens->next();
|
$tokens->next();
|
||||||
|
@ -235,4 +235,22 @@ class Render extends \ArrayObject
|
|||||||
{
|
{
|
||||||
throw new \BadMethodCallException("Unknown method " . $method);
|
throw new \BadMethodCallException("Unknown method " . $method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function __get($name)
|
||||||
|
{
|
||||||
|
if($name == 'info') {
|
||||||
|
return array(
|
||||||
|
'name' => $this->_name,
|
||||||
|
'schema' => $this->_scm,
|
||||||
|
'time' => $this->_time
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __isset($name)
|
||||||
|
{
|
||||||
|
return $name == 'info';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -918,15 +918,16 @@ class Template extends Render
|
|||||||
{
|
{
|
||||||
$is_var = false;
|
$is_var = false;
|
||||||
$vars = array(
|
$vars = array(
|
||||||
'get' => '$_GET',
|
'get' => '$_GET',
|
||||||
'post' => '$_POST',
|
'post' => '$_POST',
|
||||||
'session' => '$_SESSION',
|
'session' => '$_SESSION',
|
||||||
'cookie' => '$_COOKIE',
|
'cookie' => '$_COOKIE',
|
||||||
'request' => '$_REQUEST',
|
'request' => '$_REQUEST',
|
||||||
'files' => '$_FILES',
|
'files' => '$_FILES',
|
||||||
'globals' => '$GLOBALS',
|
'globals' => '$GLOBALS',
|
||||||
'server' => '$_SERVER',
|
'server' => '$_SERVER',
|
||||||
'env' => '$_ENV',
|
'env' => '$_ENV',
|
||||||
|
'tpl' => '$tpl->info'
|
||||||
);
|
);
|
||||||
if ($this->_options & Fenom::DENY_ACCESSOR) {
|
if ($this->_options & Fenom::DENY_ACCESSOR) {
|
||||||
throw new \LogicException("Accessor are disabled");
|
throw new \LogicException("Accessor are disabled");
|
||||||
@ -948,12 +949,6 @@ class Template extends Render
|
|||||||
case 'version':
|
case 'version':
|
||||||
$var = '\Fenom::VERSION';
|
$var = '\Fenom::VERSION';
|
||||||
break;
|
break;
|
||||||
case 'tpl':
|
|
||||||
$var = '$tpl->getName()';
|
|
||||||
break;
|
|
||||||
case 'schema':
|
|
||||||
$var = '$tpl->getScm()';
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new UnexpectedTokenException($tokens);
|
throw new UnexpectedTokenException($tokens);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user