https://github.com/oppodelldog/twig-assert
POC - twig language extention that adds assert block tag
https://github.com/oppodelldog/twig-assert
Last synced: 8 months ago
JSON representation
POC - twig language extention that adds assert block tag
- Host: GitHub
- URL: https://github.com/oppodelldog/twig-assert
- Owner: Oppodelldog
- Created: 2019-03-09T14:57:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-12T22:21:14.000Z (over 6 years ago)
- Last Synced: 2025-01-02T19:52:48.637Z (9 months ago)
- Language: PHP
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# twig-assert
This Twig Language Extension allows to **assert** the type of a view variable that is required for the template to render.Acting as a **guard-clause** it stops rendering the current templte when the assertion fails.
## Add an assertion
Simply add an type assertion to your template.
If the assertion fails, the template will not render.Let's assume a view variable **viewModelTypeA** of type **TypeA**.
```twig
{# test.twig #}
{% assert viewModelTypeA "\\TypeA" %}{{ some_view_model.getText }}
{% assert viewModelTypeA "\\TypeB" %} {# <- rendering stops here #}
{{ other_view_model.getText }}
```
Right after assertion 2 twig stops rendering the template since the assertion mismatched.