Links for Toggling the Sort Order of a MM List
Note
This feature is available from MM 2.2.
In the list output settings (CE/FE module) there is an option to allow the default sort order to be overridden (“Allow overriding the sort order”). When this option is enabled, various parameters can be set:
Slug/GET key for overriding
orderByas the key for the attribute to sort bySlug/GET key for overriding
orderDiras the key for the sort directionURL fragment if the link should jump to a specific anchor on the page

The desired links for custom sorting can be added in the MM list template or elsewhere.
Note
This feature is available from MM 2.3.
To simplify usage in the MM list template, it is possible to generate various sorting links for each attribute. There is a “toggle link” that switches to the other sort direction, as well as individual links for ascending and descending — corresponding CSS classes and an active parameter are also passed along. The complete link including CSS classes can also be generated directly.
The following snippet shows example calls for the “Name” attribute with column name name:
1<?php
2// Variant 1 with 'generateSortingLink':
3<?php if ($sortingLinkToggle = $this->generateSortingLink('name', 'toggle')): ?>
4<a href="<?= $sortingLinkToggle['href'] ?>" class="<?= $sortingLinkToggle['class'] ?>" data-escargot-ignore rel="nofollow"><?= $sortingLinkToggle['label'] ?> (toggle)</a><br>
5<?php endif; ?>
6<?php if ($sortingLinkAsc = $this->generateSortingLink('name', 'asc')): ?>
7<a href="<?= $sortingLinkAsc['href'] ?>" class="<?= $sortingLinkToggle['class'] ?>" data-escargot-ignore rel="nofollow"><?= $sortingLinkAsc['label'] ?> (asc)</a><br>
8<?php endif; ?>
9<?php if ($sortingLinkDesc = $this->generateSortingLink('name', 'desc')): ?>
10<a href="<?= $sortingLinkDesc['href'] ?>" class="<?= $sortingLinkToggle['class'] ?>" data-escargot-ignore rel="nofollow"><?= $sortingLinkDesc['label'] ?> (desc)</a><br>
11<?php endif; ?>
12
13// Variant 2 with 'renderSortingLink':
14<?= $this->renderSortingLink('name', 'toggle') ?> (toggle)<br>
15<?= $this->renderSortingLink('name', 'asc') ?> (asc)<br>
16<?= $this->renderSortingLink('name', 'desc') ?> (desc)<br>
17
18// List...
19<?php foreach ($this->data as $arrItem): ?>
Note that when linking to the default sort order settings, the slug/GET parameters are removed —
only the URL fragment is retained. The data-escargot-ignore attribute prevents the link from
being picked up by the Contao crawler for search indexing.
Calling generateSortingLink with the parameters “column name” of the attribute and sort type
returns the following values:
“attribute”: reference to the attribute
“name”: name of the attribute
“href”: link for sorting
“direction”: current sort direction (
asc||desc)“active”:
trueif this is the currently sorted attribute, otherwisefalse“class”: CSS classes
“label”: label
renderSortingLink generates a complete link — the text can be customised by adjusting the
language file.