Add twig support#1584
Open
zonky2 wants to merge 6 commits into
Open
Conversation
A matching Twig template "@Contao/metamodels/<group>/<leaf>.html.twig" now takes precedence over the legacy ".html5" template, mirroring Contao core. When no Twig template exists the legacy template is used unchanged (full BC fallback). The new MetaModels\Render\TwigTemplateSurrogate resolves the candidate via Contao's managed "@contao" filesystem loader (so the templates are Template Studio ready and support theme and project overrides) and renders it through Twig with a context built by Contao's ContextFactory. MetaModels\Render\Template consults it before including the PHP template; the render group (attribute, filter, item) is passed by the callers via TemplateFactory::createTemplate(). Only the visual "html5" format is a Twig candidate - the plain text format used for the search index and sorting stays on the PHP engine. Precedence applies in the front end and the back end. See docs/twig-templates.md for the naming scheme and how packages ship templates (twig/ namespace root with a .twig-root marker).
…through the surrogate Ship the first core Twig templates under the namespace root Resources/contao/templates/twig/.twig-root: - metamodels/item/prerendered.html.twig (from metamodel_prerendered.html5) - metamodels/filter/default.html.twig (from mm_filteritem_default.html5) FrontendFilter::renderWidget() now renders the filter widget through MetaModels\Render\Template (via TemplateFactory, group "filter") instead of a raw Contao FrontendTemplate, so filter widgets use the same @Contao/metamodels/filter/<leaf> scheme as attributes and items. Verified in the front end: item list and filter widgets render through Twig with correct output (labels, values, actions) and fall back to the legacy .html5 templates where no Twig template exists.
Ship the remaining core item and filter Twig templates: - item/unrendered, item/prerendered_debug - filter/checkbox, filter/radiobuttons, filter/linklist, filter/datepicker (each extends filter/default via Twig block inheritance) Transitional back-compat (deprecated, to be removed in 3.0 with the .html5 templates): a legacy override of the flat template name in the project "templates/" directory (or a theme folder) keeps precedence over a bundle provided Twig template, so existing customisations keep working after the upgrade. Template::hasLegacyTemplateOverride() detects such overrides using the kernel project directory, which is now injected via TemplateFactory instead of being fetched from the container. Verified in the front end across several list pages (HTTP 200).
Provide Twig versions of the Contao content element / module wrapper templates (flat @contao identifiers): ce_metamodel_list, mm_filter_default, mm_clearall_default and the pagination template mm_pagination. The item templates now include the separate @Contao/mm_actionbutton.html.twig instead of inlining the markup, so existing custom action button templates keep overriding it.
Cover MetaModels\Render\TwigTemplateSurrogate: the html5-only format gate, the empty group and missing template short-circuits, precedence of a higher priority legacy .html5 template, rendering the Twig template when it exists, and the identifier mapping (metamodels/<group>/<leaf>) for the attribute, filter and item groups including the prefix stripping.
Contao 5.7 renders be_wildcard through an auto-escaping Twig template, so the
HTML info text built for the MetaModels content element / module preview
("MM: …", "Fi: …") showed up as escaped source in the back end list. Wrap the
info text in a Twig Markup instance so it is treated as safe HTML by the Twig
be_wildcard template while still rendering correctly via the legacy .html5 one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.