ablog
ablog copied to clipboard
Postlist by tag -> handle zero items
Hi, and thanks for the work on ablog
Any suggestions on how to handle the zero posts in a postlist situation. I think current behavious is to use all posts, but what I'd like is to be able to show aletrnative content if there are no posts.
Sorry, I am not sure I follow. Do you have an example?
Hi @nabobalis thanks for the response.
If I try to make a list of posts
.. postlist:: 10
:date: %B %d, %Y
:format: {title} - {date}
:list-style: none
:tags: a-tag-without-post
And I know that there are 0 posts with that tag I'd like to show alternate content. I think current behavior is to return latest posts with any tag.
Ah ok. I understand now.
Unfortunately I don't have an answer on how to do that. If I get some time I will look into adding that as an extra feature to postlist. Ablog and how it works is still quite new to me.
Many thanks :-)
I guess the easiest might be including text in th postlist
construct itself. That way you can check inside the code, and not worry about returning the condition?
.. postlist:: 10 :date: %B %d, %Y :format: {title} - {date} :list-style: none :tags: a-tag-without-post :ifempty: More news soon
Yeah, something like that would be my initial idea as well.
Here's another possibility, based on post.py
having this logic:
if colls:
# Some stuff
else:
posts = list(blog.recent(node.attributes['length'], docname, **node.attributes))
I suspect the way to nicely implement this is something like
...
else:
if node.has_content:
node.replace_self(child)
continue
else:
posts = list(blog.recent(...))
The advantage to this approach is that it lets one define a fairly rich default by doing something like this:
.. postlist::
This is my first paragraph that shows up in an empty post list.
And this paragraph also shows up.