How to count authors in Pelican Blogs?

168 views Asked by At

I was trying to make my blog show "Authors" instead of "Author" when there are more than 1 authors for the same article.

The solution (thanks to @Avaris) is to set i = article.authors|count and that can be used as follows

<div align="right">
          {% set i = article.authors|count %}
          {% if i != 1 %}
          Authors:<br>
          {% endif %}
          {% if i == 1 %}
          Author:<br>
          {% endif %}
          {% if article.authors %}
            {% for author in article.authors %}
              <a href="{{ SITEURL }}/{{ author.url }}">{{ author }}</a><br>
            {% endfor %}
          {% endif %}
        </div>

This is different to Set variable in jinja because in Pelican I cannot find a command like lenght(authors) to obtain a number to define a condition.

0

There are 0 answers