An open API service indexing awesome lists of open source software.

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.

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 #}




```