Merge pull request #63 from ajdavis/get-siblings

New get_siblings() method
This commit is contained in:
Armin Ronacher 2016-02-01 01:32:51 -08:00
commit 481e85d4f4
6 changed files with 91 additions and 50 deletions

View File

@ -1,24 +0,0 @@
title: get_next_sibling
---
summary: Returns the next record.
---
type: method
---
body:
Get the next record in this record's parent's list of children.
If the parent record has pagination enabled, then `get_prev_sibling` and
`get_next_sibling` use the pagination query to filter and order the children.
Otherwise, the parent's standard configuration for children is used.
See [the pagination guide :ref](../../../../guides/pagination/) and the
[page order guide :ref](../../../../guides/page-order/).
## Example
```html+jinja
{% set newer = this.get_next_sibling() %}
{% if newer %}
<a href="{{ newer|url }}">Next article: {{ newer.title }}</a>
{% endif %}
```

View File

@ -1,24 +0,0 @@
title: get_prev_sibling
---
summary: Returns the previous record.
---
type: method
---
body:
Get the previous record in this record's parent's list of children.
If the parent record has pagination enabled, then `get_prev_sibling` and
`get_next_sibling` use the pagination query to filter and order the children.
Otherwise, the parent's standard configuration for children is used.
See [the pagination guide :ref](../../../../guides/pagination/) and the
[page order guide :ref](../../../../guides/page-order/).
## Example
```html+jinja
{% set older = this.get_prev_sibling() %}
{% if older %}
<a href="{{ older|url }}">Previous article: {{ older.title }}</a>
{% endif %}
```

View File

@ -0,0 +1,34 @@
title: get_siblings
---
summary: The previous and next children of this page's parent.
---
type: method
---
body:
Get the previous and next record in this record's parent's list of children.
The returned object has attributes `prev_page` and `next_page`.
Each can be a [Record :ref](../) or `None`.
If the parent record has pagination enabled, then use the pagination query to
filter and order the children. Otherwise, the parent's standard configuration
for children is used.
See [the pagination guide :ref](../../../../guides/pagination/) and the
[page order guide :ref](../../../../guides/page-order/).
## Example
```html+jinja
{% set siblings = this.get_siblings() %}
{% if siblings.prev_page %}
<a href="{{ siblings.prev_page|url }}">previous</a>
{% endif %}
{% if siblings.next_page %}
<a href="{{ siblings.next_page|url }}">next</a>
{% endif %}
```
See also: [has_prev :ref](../has_prev/) and [has_next :ref](../has_next/).

View File

@ -0,0 +1,27 @@
title: has_next
---
summary: Whether the record has a next sibling.
---
type: method
---
body:
True if there is a next record in the parent's list of children.
If the parent record has pagination enabled, then use the pagination query to
filter and order the children. Otherwise, the parent's standard configuration
for children is used.
See [the pagination guide :ref](../../../../guides/pagination/) and the
[page order guide :ref](../../../../guides/page-order/).
## Example
```html+jinja
{% if this.has_next() %}
<a href="{{ this.get_siblings().next_page|url }}">next</a>
{% else %}
<p>This is the last entry.
{% endif %}
```
See also: [has_prev :ref](../has_prev/) and [get_siblings :ref](../get_siblings/).

View File

@ -0,0 +1,27 @@
title: has_prev
---
summary: Whether the record has a previous sibling.
---
type: method
---
body:
True if there is a previous record in the parent's list of children.
If the parent record has pagination enabled, then use the pagination query to
filter and order the children. Otherwise, the parent's standard configuration
for children is used.
See [the pagination guide :ref](../../../../guides/pagination/) and the
[page order guide :ref](../../../../guides/page-order/).
## Example
```html+jinja
{% if this.has_prev() %}
<a href="{{ this.get_siblings().prev_page|url }}">previous</a>
{% else %}
<p>This is the first entry.
{% endif %}
```
See also: [has_next :ref](../has_next/) and [get_siblings :ref](../get_siblings/).

View File

@ -19,8 +19,9 @@
</div> </div>
{% endcall %} {% endcall %}
{% set older = this.get_next_sibling() %} {% set siblings = this.get_siblings() %}
{% set newer = this.get_prev_sibling() %} {% set older = siblings.next_page %}
{% set newer = siblings.prev_page %}
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-8 col-md-offset-2"> <div class="col-md-8 col-md-offset-2">