This bundle add twig template support to contao
A bundle to enable twig templates support in contao. Templates are handled like .html5 templates in contao, e.g. you can select them in your custom templates select in the backend and they will be outputted in the frontend.
- enable twig support in contao
- use twig to write contao templates
- select twig templates in your module/element custom template selection or override default templates in twig
- support for all types of templates including widgets
- use this bundle as library to work with twig templates in your own bundles with extensive template loader
- uses caching for fast performance (is disabled in dev mode)
- minimal dependencies ;)
Install via contao manager or composer:
composer require heimrichhannot/contao-twig-support-bundle
If you want to use this bundle to enable contao to support twig templates, you need to enable the template loader. You just need to add following configuration entries to your config.yml:
# config/config.yml (Contao 4.9) or app/Resources/config/config.yml (Contao 4.4) huh_twig_support: enable_template_loader: true
Now you can just create a twig template like
ce_text_custom.html.twigand add it to your projekt
templatefolder (in contao 4.4:
app/Resources/views) and you can select the template as custom Template in the text content element. You can override every core template that is parsed by
parseWidgethook. You can also add templates from bundles.
User input is encoded by contao, so you need to add the raw filter to variables if you need to output html.
If you want to use the project templates folder also in contao 4.4, just add following lines to your config.yml:
# app/Ressouces/config/config.yml twig: paths: '%kernel.project_dir%/templates': ~
|BeforeParseTwigTemplateEvent||Dispatched after twig templates was found.|
|BeforeRenderTwigTemplate||Dispatched before twig templates is rendered.|
This bundle is a great base if you want to use twig in your own bundles. Use the
HeimrichHannot\TwigSupportBundle\Filesystem\TwigTemplateLocator service to load your templates, where you need them while keeping the contao template hierarchy.
huh_twig_support: # Enable twig templates to be loaded by contao (enabled overriding core templates and select twig templates in the contao backend). enable_template_loader: false