1

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.

Community
  • 1
  • 1
pachadotdev
  • 3,345
  • 6
  • 33
  • 60
  • 1
    Possible duplicate of [Set variable in jinja](http://stackoverflow.com/questions/3727045/set-variable-in-jinja) – Akshat Mahajan Dec 13 '16 at 02:47
  • not really, because I read the documentation and the documentation does not say how to define `i = 1` where 1 is not constant but taken for the count of authors – pachadotdev Dec 13 '16 at 03:09
  • 1
    You pretty much have it. You just need to do `{% set i = article.authors|count %}`. – Avaris Dec 23 '16 at 00:42

0 Answers0