Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying for specific articles (via tag/category) in Pelican themes

Is it possible to set query parameters via jinja in Pelican template files?

index.html

{% if articles %}
    {% for article in articles_page.object_list if article.category == 'article' %}        
        #stuff
    {% endfor %}
{% endif %}

This will return articles in the article category, but only if they happen to be in the articles already queried for. The desirable setup would be to grab x articles in y category (or with y tag) - is that possible?

like image 946
Edbury Avatar asked Mar 23 '23 02:03

Edbury


1 Answers

This code snippet works for me to bring back a list of all articles matching a tag:

 {% block content %}
 <ul>
 {% for article in articles if FAVORITES_TAG in article.tags %}
   {% if loop.index <= FAVORITES_COUNT %} 
     <li><a href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a></li>
   {% endif %}
 {% endfor %}
</ul>
{% endblock %}

I set the FAVORITES_TAG and FAVORITES_COUNT variables in the config. I hope that helps.

like image 173
bestep Avatar answered Mar 24 '23 16:03

bestep