clawrock / magento2-twig-engine
Magento 2 Twig Template Engine
Installs: 132
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Type:magento2-module
Requires
- magento/framework: ~101.0|~102.0
- magento/module-store: ~100.2|~101.0
- twig/twig: ^2.6
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^6.5
- sebastian/phpcpd: ^3.0
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2024-11-08 19:40:28 UTC
README
Magento 2 - Twig Template Engine
Module implementing Twig as Magento 2 template engine. It works with default .phtml templates as fallback.
Installation
- Install module via composer
composer require clawrock/magento2-twig-engine
- Register module
php bin/magento setup:upgrade
Compatibility
- Magento 2.2 - 2.3
- PHP 7.0 - 7.2
Configuration
There is no system.xml
file, because Twig configuration should be only edited by developers.
Auto resolve option
This module can automatically look for twig files. For example if you want to use twig template in Magento\Theme\Block\Html\Title
block just add file in app/design/frontend/Vendor/theme/Magento_Theme/templates/html/title.html.twig
. If you disable auto resolve you will have to update each block template manually:
<referenceBlock name="page.main.title" template="Magento_Theme::html/title.html.twig"/>
Auto resolve option works the same as Magento 2 template resolver. For example if your theme is Luma and template is Magento_Theme::html/title.phtml
it will check possible paths in following order until first existing file:
vendor/magento/theme-frontend-luma/Magento_Theme/templates/html/title.html.twig
vendor/magento/theme-frontend-luma/Magento_Theme/templates/html/title.twig
vendor/magento/theme-frontend-luma/Magento_Theme/templates/html/title.phtml
vendor/magento/theme-frontend-blank/Magento_Theme/templates/html/title.html.twig
vendor/magento/theme-frontend-blank/Magento_Theme/templates/html/title.twig
vendor/magento/theme-frontend-blank/Magento_Theme/templates/html/title.phtml
vendor/magento/module-theme/view/frontend/templates/html/title.html.twig
vendor/magento/module-theme/view/frontend/templates/html/title.twig
vendor/magento/module-theme/view/frontend/templates/html/title.phtml
Extending
Environment options override
XML
Create module dependent on ClawRock_TwigEngine and override values in config.xml
Programmatically
Create before plugin for EnvironmentFactory and modify $options argument.
Create new Twig Extension
Create Extension class extending AbstractExtension or implementing ExtensionInterface and register it with etc/twig.xml
.
Example: ClawRock\TwigEngine\Twig\Extension\MagentoExtension
Important! You can use Magento DI in Twig Extensions.