Handling Articles

Listing Articles

Publisher have concept of Meta Loaders - one of built in loaders covers articles.

The articles loader parameters:

  • (optional) key route - id or name or array of id’s used for loading meta (if omitted then current route is used).
1
2
3
{% gimmelist article from articles %} <!-- It will use route from context -->
    <img src="{{ url(article) }}" />
{% endgimmelist %}
1
2
3
{% gimmelist article from articles with {'route': 1} %} <!-- route id -->
    <img src="{{ url(article) }}" />
{% endgimmelist %}
1
2
3
{% gimmelist article from articles with {'route': '/news'} %} <!-- route staticPrefix -->
    <img src="{{ url(article) }}" />
{% endgimmelist %}
1
2
3
{% gimmelist article from articles with {'route': ['/news', '/sport/*']} %} <!-- route staticPrefix -->
    <img src="{{ url(article) }}" />
{% endgimmelist %}

Note

'/sport/*' syntax will load articles from main route ('/sport') and all of it 1st level children (eg. '/sport/football').

1
2
3
{% gimmelist article from articles with {'route': [1, 2, 3]} %} <!-- array with routes id -->
    <img src="{{ url(article) }}" />
{% endgimmelist %}
  • (optional) key metadata - It matches article’s metadata, and you can use all metadata fields that are defined for the article, i.e.: language, located etc.
1
2
3
{% gimmelist article from articles with {'metadata':{'language':'en'}} %}
    <img src="{{ url(article) }}" />
{% endgimmelist %}
  • (optional) key keywords - It matches article’s keywords,
1
2
3
{% gimmelist article from articles with {'keywords':['keyword1', 'keyword2']} %}
    <img src="{{ url(article) }}" />
{% endgimmelist %}
  • Filtering out selected articles (useful when you want to exclude articles listed already in content list)
1
2
3
{% gimmelist article from articles without {article:[1,2]} %} <!-- pass articles ids (collected before) -->
    <img src="{{ url(article) }}" />
{% endgimmelist %}
1
2
3
{% gimmelist article from articles without {article:[gimme.article]} %} <!-- pass articles meta objects -->
    <img src="{{ url(article) }}" />
{% endgimmelist %}
  • Ordering by article comments count (set by external system)
1
2
3
{% gimmelist article from articles|order('commentsCount', 'desc') %}
    <img src="{{ url(article) }}" />
{% endgimmelist %}

Fetching first article url (when it’s changed after slug or route change)

1
2
3
{% gimme article with {slug: "test-article"} %}
    <a href="{{ original_url(article) }}">{{ article.title }}</a>
{% endgimme %}

Note

original_url function will always return valid article url. If article url was changed after publication, then it will return it’s original (first) value.