PHPackages                             schumacherfm/magento-twig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. schumacherfm/magento-twig

ActiveMagento2-module[Templating &amp; Views](/categories/templating)

schumacherfm/magento-twig
=========================

Twig template engine for Magento 2

2.1.5(3y ago)6014.8k↑71.1%20[1 issues](https://github.com/SchumacherFM/Magento2-Twig/issues)OSL-3.0PHPPHP &gt;=7.2

Since Jun 8Pushed 3y ago5 watchersCompare

[ Source](https://github.com/SchumacherFM/Magento2-Twig)[ Packagist](https://packagist.org/packages/schumacherfm/magento-twig)[ RSS](/packages/schumacherfm-magento-twig/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (7)Dependencies (5)Versions (21)Used By (0)

Magento 2 Twig Template Engine
==============================

[](#magento-2-twig-template-engine)

[Twig](http://twig.sensiolabs.org) template engine for Magento2.

This template engine is meant to be used additionally to the `.phtml` files and does not provide any `.twig` template file.

A use case would be if you write your first Magento2 module you can require this package and write all your template files in Twig.

Installation
------------

[](#installation)

1. Add dependency

```
composer require schumacherfm/magento-twig

```

2. Enable the module

```
bin/magento module:enable SchumacherFM_Twig

```

3. Update the database entries

```
bin/magento setup:upgrade

```

Events &amp; Configuration
--------------------------

[](#events--configuration)

The Twig template engine class dispatches two events so that you can modify Twig.

Event `twig_loader` with event object `loader`. You can set `loader` any other class which implements `Twig_LoaderInterface`.

Event `twig_init` with event object `twig`. You can add here more functions, filters, tags, etc.

Configuration options can be found Stores -&gt; Settings -&gt; Configuration -&gt; Advanced -&gt; Developer -&gt; Twig.

Frontend Integration
--------------------

[](#frontend-integration)

Your template files must have the file extension `.twig` to get automatically recognized.

In your layout xml files or blocks please specify the new template

```

            welcome

```

#### Example header.phtml converted to header.twig

[](#example-headerphtml-converted-to-headertwig)

```

```

```
{% if getShowPart() == 'welcome' %}
    {{ getWelcome() }}
{% endif %}

{% if getShowPart() == 'other' %}
    {{ getChildHtml()|raw }}
{% endif %}
```

#### Example breadcrumbs.phtml converted to breadcrumbs.twig

[](#example-breadcrumbsphtml-converted-to-breadcrumbstwig)

```
