Tipps und Tricks Filter

Pagination Twig Template nav und ul class

Am Beispiel von Pagination in einer Newslist als Twig Template hier ein Beispiel, wie man die "class" setzen kann für das "nav" Tag und "class" für das "ul" Tag. Die Werte kommen hier aus Bootstrap.

Achtung: Das geht erst am Contao 5.7.4, da gibt es erst die "list_attributes" Angabe

{# templates/mod_newslist.html.twig #}
{% extends '@Contao/mod_newslist' %}
{% use '@Contao/component/_pagination.html.twig' %}

{% block pagination_component %}
    {% set pagination_attributes = attrs()
        .addClass(['my-5', 'w-100'])
        .mergeWith(pagination_attributes|default)
    %}

    {% set list_attributes = attrs()
        .addClass(['d-flex', 'p-0', 'w-100', 'align-items-center', 'justify-content-center'])
        .mergeWith(list_attributes|default)
    %}

    {{ parent() }}
{% endblock %}

{% block content %}
    {% if not articles %}
        <p class="empty">{{ empty }}</p>
    {% else %}
        {{ articles|join|raw }}

        {% if pagination.object|default %}
            {% with {pagination: pagination.object} %}{{ block('pagination_component') }}{% endwith %}
        {% endif %}
    {% endif %}
{% endblock %}

Quelle: Forum