Added sort key and guide on it

This commit is contained in:
Armin Ronacher 2015-12-26 20:48:05 +01:00
parent bc74916054
commit bc60df6d26
2 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,21 @@
title: sort_key
---
summary: An integer type specific for sorting.
---
type: type
---
body:
The `sort_key` type is similar to the `integer` type which is one of the most
basic ones in Lektor. It can store arbitrary natural numbers both negative and
positive. It's intended for giving pages a sort order. The reason it's a
special type is that future versions of Lektor can take advantage of this to
implement a widget for ordering.
## Field Usage
```ini
[fields.sort_key]
label = Sort order
type = sort_key
```

View File

@ -0,0 +1,51 @@
title: Page Order
---
summary: How to get your pages ordered.
---
body:
Pages can generally have an order defined. This order comes from the
configuration of children in the parent model or can be explicitly provided.
This page guides you through all the different options you have.
## Default Configuration
The most common way to get order into your pages is the configuration for
children. This way an order can be defined that is used by default for any
query involving the children of a page. So what can you order by? You can
order by any field you want. For instance to order by the name of a page
you can do this:
```ini
[children]
model = project
order_by = name
```
This will automatically order the `.children` query by the name of a project.
You can define more than one ordering. For instance you could order blog
posts by dates in decreasing order and secondarily by the blog title:
```ini
[children]
model = blog-post
order_by = -pub_date, title
```
A minus sign as prefix reverses the order.
## Specific Order
But what to do if you want to order something specifically? In that case you
can use the [sort_key :ref](../../api/db/types/sort-key/) type and configure
that:
```ini
[children]
model = doc-page
order_by = sort_key
```
Currently you need to explicitly give numbers in this field but future versions
of Lektor will provide support for automatically reordering them in the admin
panel.