{"id":22993730,"url":"https://github.com/schumacherfm/magento2-twig","last_synced_at":"2025-04-08T04:19:14.951Z","repository":{"id":25810902,"uuid":"29249908","full_name":"SchumacherFM/Magento2-Twig","owner":"SchumacherFM","description":"Twig Template Engine for Magento2","archived":false,"fork":false,"pushed_at":"2023-04-19T14:04:24.000Z","size":49,"stargazers_count":62,"open_issues_count":1,"forks_count":21,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-24T09:17:29.344Z","etag":null,"topics":["magento","magento2","php","template-engine","twig","twig-template-engine"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SchumacherFM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-01-14T15:11:15.000Z","updated_at":"2024-10-07T13:09:12.000Z","dependencies_parsed_at":"2025-01-16T12:18:46.711Z","dependency_job_id":"1b774199-1419-4e9c-bac5-b9d0f4e470a7","html_url":"https://github.com/SchumacherFM/Magento2-Twig","commit_stats":{"total_commits":58,"total_committers":14,"mean_commits":4.142857142857143,"dds":0.6551724137931034,"last_synced_commit":"d66458ef0eda3ab50880d83c89f8b6f827a5a95b"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SchumacherFM%2FMagento2-Twig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SchumacherFM%2FMagento2-Twig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SchumacherFM%2FMagento2-Twig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SchumacherFM%2FMagento2-Twig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SchumacherFM","download_url":"https://codeload.github.com/SchumacherFM/Magento2-Twig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247773726,"owners_count":20993639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["magento","magento2","php","template-engine","twig","twig-template-engine"],"created_at":"2024-12-15T05:14:19.386Z","updated_at":"2025-04-08T04:19:14.933Z","avatar_url":"https://github.com/SchumacherFM.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Magento 2 Twig Template Engine\n============\n\n[Twig](http://twig.sensiolabs.org) template engine for Magento2.\n\nThis template engine is meant to be used additionally to the `.phtml` files and does not \nprovide any `.twig` template file.\n\nA use case would be if you write your first Magento2 module you can require this package\nand write all your template files in Twig.\n\n\nInstallation\n------------\n1. Add dependency\n```\ncomposer require schumacherfm/magento-twig\n```\n\n2. Enable the module\n```\nbin/magento module:enable SchumacherFM_Twig\n```\n\n3. Update the database entries\n```\nbin/magento setup:upgrade\n```\n\nEvents \u0026 Configuration\n-------------\n\nThe Twig template engine class dispatches two events so that you can modify Twig.\n\nEvent `twig_loader` with event object `loader`. You can set `loader` any other class which implements\n`Twig_LoaderInterface`. [http://twig.sensiolabs.org/doc/api.html#loaders](http://twig.sensiolabs.org/doc/api.html#loaders)\n\nEvent `twig_init` with event object `twig`. You can add here more functions, filters, tags, etc.\n[http://twig.sensiolabs.org/doc/advanced.html](http://twig.sensiolabs.org/doc/advanced.html)\n\nConfiguration options can be found Stores -\u003e Settings -\u003e Configuration -\u003e Advanced -\u003e Developer -\u003e Twig.\n\nFrontend Integration\n--------------------\n\nYour template files must have the file extension `.twig` to get automatically recognized.\n\nIn your layout xml files or blocks please specify the new template\n\n```xml\n\u003creferenceBlock name=\"top.links\"\u003e\n    \u003cblock class=\"Magento\\Theme\\Block\\Html\\Header\" template=\"html/header.twig\" name=\"header\" as=\"header\" before=\"-\"\u003e\n        \u003carguments\u003e\n            \u003cargument name=\"show_part\" xsi:type=\"string\"\u003ewelcome\u003c/argument\u003e\n        \u003c/arguments\u003e\n    \u003c/block\u003e\n\u003c/referenceBlock\u003e\n```\n\n#### Example header.phtml converted to header.twig\n\n```php\n\u003c?php switch ($this-\u003egetShowPart()):\n    case 'welcome': ?\u003e\n        \u003cli class=\"greet welcome\"\u003e\u003c?php echo $this-\u003egetWelcome() ?\u003e\u003c/li\u003e\n    \u003c?php break; ?\u003e\n    \u003c?php case 'other': ?\u003e\n        \u003c?php echo $this-\u003egetChildHtml(); ?\u003e\n    \u003c?php break; ?\u003e\n\u003c?php endswitch; ?\u003e\n```\n\n```twig\n{% if getShowPart() == 'welcome' %}\n    \u003cli class=\"greet welcome\"\u003e{{ getWelcome() }}\u003c/li\u003e\n{% endif %}\n\n{% if getShowPart() == 'other' %}\n    {{ getChildHtml()|raw }}\n{% endif %}\n```\n\n#### Example breadcrumbs.phtml converted to breadcrumbs.twig\n\n```php\n\u003c?php if ($crumbs \u0026\u0026 is_array($crumbs)) : ?\u003e\n\u003cdiv class=\"breadcrumbs\"\u003e\n    \u003cul class=\"items\"\u003e\n        \u003c?php foreach ($crumbs as $crumbName =\u003e $crumbInfo) : ?\u003e\n            \u003cli class=\"item \u003c?php echo $crumbName ?\u003e\"\u003e\n            \u003c?php if ($crumbInfo['link']) : ?\u003e\n                \u003ca href=\"\u003c?php echo $crumbInfo['link'] ?\u003e\" title=\"\u003c?php echo $this-\u003eescapeHtml($crumbInfo['title']) ?\u003e\"\u003e\n                    \u003c?php echo $this-\u003eescapeHtml($crumbInfo['label']) ?\u003e\n                \u003c/a\u003e\n            \u003c?php elseif ($crumbInfo['last']) : ?\u003e\n                \u003cstrong\u003e\u003c?php echo $this-\u003eescapeHtml($crumbInfo['label']) ?\u003e\u003c/strong\u003e\n            \u003c?php else: ?\u003e\n                \u003c?php echo $this-\u003eescapeHtml($crumbInfo['label']) ?\u003e\n            \u003c?php endif; ?\u003e\n            \u003c/li\u003e\n        \u003c?php endforeach; ?\u003e\n    \u003c/ul\u003e\n\u003c/div\u003e\n\u003c?php endif; ?\u003e\n```\n\n```twig\n{% if crumbs %}\n\u003cdiv class=\"breadcrumbs\"\u003e\n    \u003cul class=\"items\"\u003e\n    {% for crumbName,crumbInfo in crumbs %}\n        \u003cli class=\"item {{ crumbName }}\"\u003e\n            {% if crumbInfo.link %}\n                \u003ca href=\"{{ crumbInfo.link }}\" title=\"{{ crumbInfo.title }}\"\u003e\n                    {{ crumbInfo.label }}\n                \u003c/a\u003e\n            {% elseif crumbInfo.last %}\n                \u003cstrong\u003e{{ crumbInfo.label }}\u003c/strong\u003e\n            {% else %}\n                {{ crumbInfo.label }}\n            {% endif %}\n        \u003c/li\u003e\n    {% endfor %}\n    \u003c/ul\u003e\n\u003c/div\u003e\n{% endif %}\n```\n\n#### Access helper methods\n\nWrite in your `.twig` file:\n\n```twig\n{{ helper(\"Magento\\\\Core\\\\Helper\\\\Url\").getHomeUrl() }}\n```\n\nTests\n-----\n\n@todo\n\nSupport / Contribution\n----------------------\n\nReport a bug using the issue tracker or send us a pull request.\n\nInstead of forking I can add you as a Collaborator IF you really intend to develop on this module. Just ask :-)\n\nI am using that model: [A successful Git branching model](http://nvie.com/posts/a-successful-git-branching-model/)\n\nFor versioning have a look at [Semantic Versioning 2.0.0](http://semver.org/)\n\nHistory\n-------\n\n#### 2.0.0\n\n- Added Magento 2.4.0 compatibility\n- Removed helper functions from `app/functions.php` since the file is no longer available in Magento 2.4\n- Removed deprecated function `layoutBlock` from twig environment\n- Updated to twig to 3.0.* \n\nCompatibility\n-------------\n\n- Magento \u003e= 2\n- php \u003e= 5.4.0\n\nLicense\n-------\n\nOSL-30\n\nAuthor\n------\n\n[Cyrill Schumacher](http://cyrillschumacher.com)\n\n[My pgp public key](http://www.schumacher.fm/cyrill.asc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschumacherfm%2Fmagento2-twig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschumacherfm%2Fmagento2-twig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschumacherfm%2Fmagento2-twig/lists"}