contao / contao

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

Steps to get rid of the Twig experimental state #3566

Open m-vo opened 2 years ago

m-vo commented 2 years ago

In this issue, I'd like to track things that should happen with our Twig implementation become it can become part of the BC promise. I'll update the issue over time.

aschempp commented 2 years ago

should we also have support to edit Twig templates in the back end? Or is that already given?

m-vo commented 2 years ago

should we also have support to edit Twig templates in the back end? Or is that already given?

This should already work, we only need to add some logic that refreshes the template cache once saved. I added this to the list.

aschempp commented 2 years ago

I can edit files that live in /templates, but I cannot choose Twig templates to add a new template override in my root folder.

m-vo commented 2 years ago

Correct, that needs to be added. But we'll have to rework this whole template selector anyways so that you will get the right templates.

aschempp commented 2 years ago

I know. But it should be on this list, right? 😉

fkaminski commented 2 years ago

Just a reminder. If you put {{ dump() }} in the Twig template it works in debug mode. Otherwise you get an error message:

Uncaught PHP Exception Twig\Error\SyntaxError: "Did you forget to run "composer require symfony/debug-bundle"?"

m-vo commented 2 years ago

If you put {{ dump() }} in the Twig template it works in debug mode. Otherwise you get an error message:

Cannot confirm this. Please make sure the symfony/twig-bridge got installed in your application and open up an issue if the error still persists after a composer update. The dump() function should return nothing in production but not fail.

fritzmg commented 2 years ago

I can confirm the problem. Using

{% extends '@Contao/fe_page' %}

{% block main %}
  {{ dump('foo') }}
  <h1>Hello from Twig!</h1>
  {{ parent() }}
{% endblock %}

will yield

[2021-12-21T10:54:23.936147+00:00] request.CRITICAL: Uncaught PHP Exception Twig\Error\SyntaxError: "Did you forget to run "composer require symfony/debug-bundle"? Unknown function "dump" in "@Contao/fe_page.html.twig"." at vendor\symfony\twig-bridge\UndefinedCallableHandler.php line 96 {"exception":"[object] (Twig\\Error\\SyntaxError(code: 0): Did you forget to run \"composer require symfony/debug-bundle\"? Unknown function \"dump\" in \"@Contao/fe_page.html.twig\". at vendor\\symfony\\twig-bridge\\UndefinedCallableHandler.php:96)"} []

This error is in fact thrown by symfony/twig-bridge.