2023-03-09 23:16:18 +01:00
|
|
|
# Static Classes
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-03-09 23:16:18 +01:00
|
|
|
You can directly access static classes. The syntax is roughly the same as in
|
2021-12-03 11:59:22 +01:00
|
|
|
PHP.
|
|
|
|
|
|
|
|
> **Note**
|
|
|
|
>
|
|
|
|
> Direct access to PHP classes is not recommended. This ties the
|
|
|
|
> underlying application code structure directly to the presentation,
|
|
|
|
> and also complicates template syntax. It is recommended to register
|
|
|
|
> plugins which insulate templates from PHP classes/objects. Use at your
|
|
|
|
> own discretion. See the Best Practices section of the Smarty website.
|
|
|
|
|
2023-03-09 23:16:18 +01:00
|
|
|
## Examples
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-03-09 23:16:18 +01:00
|
|
|
**class constant BAR**
|
|
|
|
```smarty
|
|
|
|
{assign var=foo value=myclass::BAR}
|
|
|
|
```
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-03-09 23:16:18 +01:00
|
|
|
**method result**
|
|
|
|
```smarty
|
|
|
|
{assign var=foo value=myclass::method()}
|
|
|
|
```
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-03-09 23:16:18 +01:00
|
|
|
**method chaining**
|
|
|
|
```smarty
|
|
|
|
{assign var=foo value=myclass::method1()->method2}
|
|
|
|
```
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-03-09 23:16:18 +01:00
|
|
|
**property bar of class myclass**
|
|
|
|
```smarty
|
|
|
|
{assign var=foo value=myclass::$bar}
|
|
|
|
```
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-03-09 23:16:18 +01:00
|
|
|
**using Smarty variable bar as class name**
|
|
|
|
```smarty
|
|
|
|
{assign var=foo value=$bar::method}
|
|
|
|
```
|