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

Postlist by tag -> handle zero items #15

Open
plaindocs opened this issue Mar 21, 2018 · 6 comments
Open

Postlist by tag -> handle zero items #15

plaindocs opened this issue Mar 21, 2018 · 6 comments

Comments

@plaindocs
Copy link
Contributor

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.

@nabobalis
Copy link
Contributor

Sorry, I am not sure I follow. Do you have an example?

@plaindocs
Copy link
Contributor Author

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.

@nabobalis
Copy link
Contributor

nabobalis commented Mar 26, 2018

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.

@plaindocs
Copy link
Contributor Author

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
📅 %B %d, %Y
:format: {title} - {date}
:list-style: none
:tags: a-tag-without-post
:ifempty: More news soon

@nabobalis
Copy link
Contributor

Yeah, something like that would be my initial idea as well.

@rayalan
Copy link
Contributor

rayalan commented Aug 18, 2019

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.

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

No branches or pull requests

3 participants