[Pelican] Get Partials Pages or Articles in Theme


Inspired by the answer to re-order pages in [1], this post shows how to get partial pages or articles with specific metadata by Jinja2 built-in selectattr in the theme.

Illustrate by example, assume we want to get pages of which order is 2 in index.html in theme:

(metadata order is 2 in reStructuredText):

:order: 2

(metadata order is 2 in Markdown):

Order: 2

You can select by Jinja2 built-in selectattr filter in index.html in theme as follows:

{% for page in pages|selectattr("order", "equalto", "2") %}
  <div>Title: {{ page.title }}</div>
{% endfor %}

Tested on: Ubuntu Linux 16.10, Python 2.7.12+, Pelican 3.7.0.


References:

[1]

pelican page order - Google search

Ordering content - Settings — Pelican latest documentation

python - How can I control the order of pages from within a pelican article category? - Stack Overflow

[2]

TemplateRuntimeError: no test named - Google search

python - How do I filter a collection in a jinja2 template ? - Stack Overflow