Outputting the Attribute Description in a Template

In the list template, the name or label of an attribute is available via the attributes node.

If you also want access to the description from the attribute settings, you can make the following adjustment in the metamodels_prerendered.html5 template:

 1<?php
 2
 3/**
 4 * Add description.
 5 */
 6
 7use Contao\System;
 8use MetaModels\IMetaModel;
 9
10/** @var IMetaModel $model */
11$model      = $this->items->getItem()->getMetaModel();
12$attributes = $model->getAttributes();
13
14$attributeDescriptions = [];
15foreach ($attributes as $attribute) {
16    if (empty($attribute->getColName())) {
17        continue;
18    }
19    $attributeDescriptions[$attribute->getColName()] = $attribute->get('description');
20}
21
22// Debug.
23if (System::getContainer()->get('kernel')->isDebug()) {
24    dump($this->data);
25}
26?>
27<?php if (\count($this->data)): ?>
28    <div class="layout_full">
29// ....

To explain: with $this->items->getItem() we retrieve one item — since attribute data never changes, one item is sufficient to query the MetaModel and its attributes. The foreach is just for easier handling in the rest of the template. The whole thing could also be extracted more elegantly into a helper — see the CK23 talk

In the further output, the description can be accessed via the column name of the attribute —
e.g. <?= $attributeDescriptions['firstname'] ?? '' ?>

For multilingual models, the description matching the frontend language is output.