fenom/docs/operators.md

68 lines
957 B
Markdown
Raw Normal View History

2013-02-21 22:47:24 +04:00
Operators
=========
### Math
2013-02-21 22:47:24 +04:00
Operators: `+ - / *`
2013-02-21 22:47:24 +04:00
```smarty
{$a + $b * $c/$d - $e*5 + 1e3}
```
2013-02-21 22:47:24 +04:00
### Boolean
2013-02-21 22:47:24 +04:00
Operators: `|| && and or < > <= >= == === !== !=`
2013-02-21 22:47:24 +04:00
```smarty
{if $a && $b >= 5 && $c != 3} {/if}
```
2013-02-21 22:47:24 +04:00
### Bitwize
2013-02-21 22:47:24 +04:00
Operators: `| & << >> |= &= <<= >>=`
2013-02-21 22:47:24 +04:00
```smarty
{if $a & 1} {var $b |= $flags} {/if}
```
2013-02-21 22:47:24 +04:00
### Unary
Operators: `^ ~ - !`
```smarty
{var $b |= $flags & ^$c}
```
### Ternar
Operators: `? :`
```smarty
{var $a = true}
{$a ? 5 : 10} {* outputs 5 *}
{var $a = false}
{$a ? 5 : 10} {* outputs 10 *}
```
### Variable operator
Checking variable value
```smarty
{if $a?} {* instead of {if !empty($a)} *}
```
Checking variable existence
```smarty
{if $a!} {* instead of {if isset($a)} *}
```
Get default if variable is empty
```smarty
{$a?:"some text"} {* instead of {if empty($a) ? "some text" : $a} *}
```
Get default if variable doesn't exist
```smarty
{$a!:"some text"} {* instead of {if isset($a) ? $a : "some text"} *}
```