9. Change the sort order

So far, the pages have been displayed in the default sort order: by change date, descending, so the most recently changed pages come first. To be able to set our own order, we need a new input field.

Switch to the module “ Structure”. Right-click the content area “Pages” and choose “ Input fields” from the context menu. The input fields of the area appear.

Click the button “Create” above the list. A selection of field types appears. In the section “META FIELDS”, click “Position after...”.

This time, the name cannot be changed in the input form.
The label contains the pre-filled, somewhat cryptic value #record.field_position. This is a “snippet”.

A snippet stores one text per language version: A user whose backend language is set to “English” sees the label “Position after...”, while a user who has set it to “Spanish” sees “Posición después de...”.
You can select a snippet with the button “” on the far right.

After you click Save, the field appears in the list of input fields.

Click the tab “Settings” and then the button “ Edit”.
The field “Default sorting” already contains the new field “position”, and the “Sort order” has already been changed to “ascending”.
Click “Cancel” and switch to the module “ Templates”: The new sort order should now also apply in the frontend (on the website).

In the code of the template “page_default”, we extend the command CMS:SELECT:

(CMS:SELECT navigation
  filter[area]=pages
  sort=position
  order=asc
)

or, written differently:

(CMS:SELECT navigation
  filter[area]=pages
  sort="position asc"
)

asc = ascending
desc = descending

After saving, you can see the result on the website.