mage-obsidian/module-modern-frontend-twig

Optional Twig template engine for MageObsidian ModernFrontend. Installing it registers a .twig engine alongside Magento's native .phtml.

Maintainers

Package info

github.com/mage-obsidian/module-modern-frontend-twig

Type:magento2-module

pkg:composer/mage-obsidian/module-modern-frontend-twig

Statistics

Installs: 1

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

2.0.1 2026-06-23 00:25 UTC

This package is auto-updated.

Last update: 2026-06-23 00:26:50 UTC


README

Optional add-on for mage-obsidian/module-modern-frontend. Installing this module registers a .twig template engine alongside Magento's native .phtml; removing it leaves only .phtml. Nothing else opts in — the engine is enabled by the module's presence.

How it works

Magento dispatches a block's template by file extension (Magento\Framework\View\Element\Template::fetchViewTemplateEnginePool). This module adds a twig entry to that engine map, so a block whose template ends in .twig is rendered by Twig while every .phtml keeps using the PHP engine. .twig and .phtml coexist in the same theme, and the theme fallback resolves .twig overrides exactly like .phtml.

What you get over phtml

  • HTML auto-escaping on by default — the main security gain; opt out per value with Twig's raw.
  • Twig inheritance ({% extends %} / {% block %}) and includes, resolved through the Magento theme fallback (use Vendor_Module::path.twig names).
  • The MageObsidian bridge, so a .twig mounts Vue islands like a .phtml:
    • {{ render_vue('Vendor_Module::Component', { prop: value }) }}
    • {{ child_html('alias') }}, {{ hero_icon('check', 'solid', '24') }}
    • {{ vite_url(path) }}, {{ component_path(name) }}, {{ view_file_url(fileId) }}
    • filters mirroring $escaper: |escape_url, |escape_html_attr, |escape_js, |escape_css
  • Block data via {{ block.getX() }} / {{ block.getData('x') }}.

Compiled templates are cached under var/cache/twig. In developer mode templates auto-reload on change and strict_variables / debug are enabled.

Note: this engine improves server-template ergonomics. It does not change runtime/browser performance — that is governed by the Vue/Vite/Tailwind output.

Documentation

For more details, visit the official documentation.