MetaModels
2.4
  • Introduction to MetaModels
  • Feature Overview
  • Installing and Updating MetaModels
  • Components of a MetaModel
  • The First MetaModel
  • Extensions
  • MetaModels “Cookbook”
    • MetaModels “Checklists”
    • Symfony and MM 2.x Tips
    • Debugging
    • Input Mask
    • Filter
    • Tips for Frontend Output
    • Template Customisations
      • Outputting the Attribute Description in a Template
      • Links for Toggling the Sort Order of a MM List
      • Custom Parameters for the MM List Output in the Frontend
      • Automatic Redirect from Detail Page to List Page or “Error 404”
      • Simple Date Picker for the From-To Filter Rule via Flatpickr Integration
      • Creating FE Templates via Content Elements
      • Outputting Structured Data in the FE Template
      • Working with Images in Templates
    • Tips (Miscellaneous)
    • Special Tasks
    • Other Websites with Tutorials, Tips, and Videos
  • Videos and Podcasts about MetaModels
  • MetaModels Reference and API
  • Imprint, Privacy Policy, Licence, Credits
MetaModels
  • MetaModels “Cookbook”
  • Template Customisations
  • Links for Toggling the Sort Order of a MM List
  • Edit on GitHub

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 orderBy as the key for the attribute to sort by

  • Slug/GET key for overriding orderDir as the key for the sort direction

  • URL fragment if the link should jump to a specific anchor on the page

img_sorting_options

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”: true if this is the currently sorted attribute, otherwise false

  • “class”: CSS classes

  • “label”: label

renderSortingLink generates a complete link — the text can be customised by adjusting the language file.

Previous Next

© Copyright 2026, Team MetaModels. Last updated on 09-10-2026.