CE Download, Link eine CSS Klasse hinzufügen

Manchmal ist es nötig, dem Link eine CSS Klasse über das Template hinzuzufügen.

Das Beispiel zeigt, wie das bei Verwendung von Twig-Templates anzupassen ist.

Nur für das Download Inhaltselement:

{# templates/content_element/download.html.twig #}
{% extends "@Contao/content_element/download.html.twig" %}

{% set download_link_attributes = attrs()
    .addClass('foobar')
    .mergeWith(download_link_attributes|default)
%}

Nur für das Downloads Inhaltselement:

{# templates/content_element/downloads.html.twig #}
{% extends "@Contao/content_element/downloads.html.twig" %}

{% set download_link_attributes = attrs()
    .addClass('foobar')
    .mergeWith(download_link_attributes|default)
%}

Für alles das die _download Komponente benutzt:

{# templates/component/_download.html.twig #}
{% use "@Contao/component/_download.html.twig" %}

{% set download_link_attributes = attrs()
    .addClass('foobar')
    .mergeWith(download_link_attributes|default)
%}

Quelle: GitHub

Nachtrag: Symfony Cache musst in Contao 5.3 auf jeden Fall gelöscht werden, sonst greifen die Änderungen nicht. Mit dem Template-Studio in Contao 5.6 ist das (manuelle) Löschen des Symfony Caches dann nicht mehr erforderlich.