https://github.com/m-vo/contao-twig
Replace your Contao php templates with Twig templates.
https://github.com/m-vo/contao-twig
Last synced: about 2 months ago
JSON representation
Replace your Contao php templates with Twig templates.
- Host: GitHub
- URL: https://github.com/m-vo/contao-twig
- Owner: m-vo
- Created: 2020-03-19T11:12:58.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-28T12:28:42.000Z (about 4 years ago)
- Last Synced: 2025-03-17T04:11:21.538Z (about 2 months ago)
- Language: PHP
- Size: 31.3 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Twig for Contao Templates
### How to use
1. Make sure you have your `twig.default_path` set. For example like this:
```yaml
twig:
default_path: '%kernel.project_dir%/templates'
```2. Put a template you want to provide as a twig version inside your template
directory (can be any subdirectory). Name it like the Contao template
but with `.html.twig` as file extension instead of `.html5`.
For example put a `ce_downloads.html.twig` file under `templates/Contao`.
3. Rebuild your cache (the filesystem is scanned for templates in a compiler pass).
**Note**: for a better DX your templates will always
be loaded in the *dev* environment.
That's it. Your new template is now rendered instead. It has the same context
as the existing Contao one would have (`Template->getData()`). :sparkles:#### Caveats
As Contao uses input encoding, you'll need to deal for already encoded variables
yourself by adding the `|raw` filter. Use with caution and be sure you know what
you are doing.Some contao templates contain closures that won't be evaluated by Twig - if you
want to use them wrap them in the `fn()` function shipping with this bundle.
This will simply execute them and return the 'safe' output (no need for `|raw`).
#### Example
```twig
{# templates/Contao/ce_downloads.html.twig #}
```