docs icon indicating copy to clipboard operation
docs copied to clipboard

Wartungstemplate anpassen in Contao 5.5

Open CMSworker opened this issue 11 months ago • 12 comments

Beim Update auf Contao 5.5.2 war mir aufgefallen, dass das angepasste Wartungstemplate (Anleitung Logo ändern) in /templates/bundles/ContaoCoreBundle/Error/layout.html.twig nicht mehr greift.

Im Core hat das Template einen Unterstrich im Dateinamen, aber eine Anpassung des eigenen Templates in /templates/bundles/ContaoCoreBundle/Error/_layout.html.twig (mit Leeren des Prod-Cache) hat das Problem nicht behoben.

Ich nehme an, das kam mit der Einführung des "Template Studio" in Contao 5.5.0?

Mein erster Versuch, im Backend > Template Studio das Template unter "error > error/_layout" komplett zu überschreiben, hat nicht geklappt (hatte den Inhalt des Ausgangstemplate aus Schritt 1 komplett kopiert, dann auf "Create your Template" geklickt, den kopierten Code dort eingefügt und gespeichert -> es wurde danach wieder nur das Standard-Überschreiben-Template angezeigt "@ extends... Adjust how any blocks of parent or used component templates are rendered.")

Ich habe daraufhin in einem externen Editor die Datei /template/error/_layout.html.twig bearbeitet, den kompletten Original-Code dort eingefügt, meine Anpassungen gemacht, gespeichert und danach im Manager den Prod-Cache geleert, das hat dann geklappt und im Template Studio wird nun auch angezeigt "This template overwrites all previously defined content because it does not extend from @ Contao/error/_layout.html.twig".

Ich vermute, das betrifft alle, die ein angepasstes Wartungstemplate verwenden. Vielleicht sollte auch zusätzlich zur Anleitung, wie man das Wartungstemplate anpasst, auch auf der Seite "Update und Migration" ein Hinweis ergänzt werden, dass mit dem Update auf 5.5 Wartungstemplates anders angepasst werden müssen?

CMSworker avatar Mar 05 '25 05:03 CMSworker

~The documentation is wrong here as this is not the correct template (and never was). I will create a PR for the documentation accordingly.~

~There have been no changes in Contao 5 regarding the error templates in Contao 5.5 as far as I am aware.~

fritzmg avatar Mar 05 '25 09:03 fritzmg

Im Core hat das Template einen Unterstrich im Dateinamen

~That is not the case btw., see the available templates here: https://github.com/contao/contao/tree/5.5.2/core-bundle/templates/Error~

fritzmg avatar Mar 05 '25 09:03 fritzmg

Basiert das nicht auf dieser Datei? https://github.com/contao/contao/blob/5.5.2/core-bundle/contao/templates/twig/error/_layout.html.twig

Um Missverständnisse zu vermeiden: Ich meinte schon das allgemeine Error-Layout-Template, nicht nur speziell "Service unavailable"...

Also beispielsweise, um in allen Fehlerseiten ein angepasstes Logo zu haben, CSS-Styles abändern... vor 5.5 hat das wie derzeit in der Anleitung beschrieben funktioniert. Um solche Anpassungen mit Twig-Vererbung machen zu können (ohne das komplette Error-Layout-Template überschreiben zu müssen), wären im Contao-Standard-Error-Layout-Template weitere Blöcke nötig (z.B. innerhalb der < style >-Sektion, am Anfang direkt nach < body >, um das Contao-SVG-Logo...)

CMSworker avatar Mar 05 '25 09:03 CMSworker

Actually the documentation also mentions adjusting all error templates accordingly.

The change was introduced in #7659.

@contao/developers the discussed BC layer does not seem to work then - nor can it really work, can it? The new error templates only use the new template namespace, so the old templates can never really have any effect.

fritzmg avatar Mar 05 '25 10:03 fritzmg

I think the BC layer was incorrectly built. It adds BC if someone rendered the error template manually, instead of adding BC if someone changed the original template.

aschempp avatar Mar 06 '25 07:03 aschempp

I don't understand the issue. The same templates as before are rendered from the code. They just got a new parent template they extend from (the new location).

m-vo avatar Mar 06 '25 08:03 m-vo

@m-vo this is what we have documented:

Customize logo

In this example we do this for all error templates. For an update-safe adaptation we copy the original template vendor/contao/core-bundle/templates/Error/layout.html.twig to templates/bundles/ContaoCoreBundle/Error/.

This does not work anymore since https://github.com/contao/contao/pull/7659. A templates/bundles/ContaoCoreBundle/Error/layout.html.twig will be ignored.

fritzmg avatar Mar 06 '25 09:03 fritzmg

There's no BC promise for templates anyway so why don't we just fix the docs?

Toflar avatar Mar 06 '25 12:03 Toflar

@Toflar because we decided to have the BC layer in order to not make things unnecessarily difficult for users. See

  • https://github.com/contao/contao/pull/7659#issuecomment-2437294997
  • https://github.com/contao/contao/pull/7659#issuecomment-2476516289

If the BC layer does not work as intended and we do not want to fix this, we can just remove it anyway.

fritzmg avatar Mar 06 '25 12:03 fritzmg

As discussed in the Contao call we want to try to fix the template inheritance so that this will work in a BC way again.

fritzmg avatar Mar 06 '25 16:03 fritzmg

See https://github.com/contao/contao/pull/8185

The documentation should still be updated. For new installations (5.5+) you would rather adjust the templates directly from the @Contao namespace.

m-vo avatar Mar 07 '25 13:03 m-vo

The documentation should still be updated.

Yes 👍

fritzmg avatar Mar 07 '25 13:03 fritzmg