contao / contao

Contao Open Source CMS
https://contao.org
GNU Lesser General Public License v3.0
350 stars 159 forks source link

Support Twig for widgets #3565

Closed m-vo closed 3 years ago

m-vo commented 3 years ago

Affected version(s)

Contao 4.12

Description

Currently, TemplateInheritance#renderTwigSurrogateIfExists() only renders a surrogate if the object is a Template instance. We're doing this so we can reliably build the right context for the Twig version (injecting $arrData making the methods available and so on…).

https://github.com/contao/contao/blob/82286f4c90e3bf2bc7857ddca6db7823fe271738/core-bundle/src/Resources/contao/library/Contao/TemplateInheritance.php#L365-L368

We're also having widgets, though that are using the TemplateInheritance.

abstract class Widget extends Controller
{
    use TemplateInheritance;

    // …
}

This for instance means it's currently not possible to overwrite form_textfield with form_textfield.html.twig.

We can of course allow other classes as well in the check but we must then also make sure we're building the right context e.g. with a new ContextHelper::fromContaoWidget() method.

aschempp commented 3 years ago

why is the context different in Widgets than in other templates?

m-vo commented 3 years ago

The Template classes store the context in $arrData, Widget directly as fields. Both with different getter magic.

m-vo commented 3 years ago

see #3626