Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The post_list plugin prevents 'else' functionality in templates #3436

Closed
devilgate opened this issue Jul 13, 2020 · 0 comments
Closed

The post_list plugin prevents 'else' functionality in templates #3436

devilgate opened this issue Jul 13, 2020 · 0 comments
Labels

Comments

@devilgate
Copy link
Contributor

Environment

Python Version:

3.7.8

Nikola Version:

8.1.1

Operating System:

Mac OS Catalina (10.15.5) / Ubuntu 19.10

Description:

In the default template for the post-list plugin, namely post_list_directive.tmpl

{% if posts %}
    <ul class="post-list">
    ...

Which suggests that there is some possibility that the template will be called with no posts.

While in list_post.tmpl, which you can also use with post-list, we have this:

    {% if posts %}
    <ul class="postlist">
    {% for post in posts %}
        <li><time class="listdate" datetime="{{ post.formatted_date('webiso') }}" title="{{ post.formatted_date(date_format)|e }}">{{ post.formatted_date(date_format)|e }}</time> <a href="{{ post.permalink() }}" class="listtitle">{{ post.title()|e }}</a></li>
    {% endfor %}
    </ul>
    {% else %}
    <p>{{ messages("No posts found.") }}</p>
    {% endif %}

Which is obviously expected to be able to handle the situation when there are no posts.

However, when the plugin returns no posts, the else block is not executed. In fact, it appears that the template is not called at all when no posts are returned.

This is because of these lines in post_list.py, at around lines 221-222:

        if not posts:
            return '', []

It seems that because the empty values are returned, processing is not passed to the template. Removing those lines fixes the problem and allows the template's else clause to work.

I can't see that this change breaks anything else, so I'll submit a pull request for it, unless someone has an objection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant