post-list in template

12 views
Skip to first unread message

Hartmut Goebel

unread,
Apr 1, 2023, 1:33:30 PM4/1/23
to nikola-discuss
Hi,

I wold like to list the newest 5 blog-posts in a side-column on every
page. Can I use sort-codes in templates?

What is the best way to do this?

(I'm aware that this most probably will lead to a full rebuild when
adding posts.)

--
Regards
Hartmut Goebel

| Hartmut Goebel | h.go...@crazy-compilers.com |
| www.crazy-compilers.com | compilers which you thought are impossible |

Chris Warrick

unread,
Apr 1, 2023, 3:20:47 PM4/1/23
to nikola-...@googlegroups.com
On Sat, 1 Apr 2023 at 19:33, Hartmut Goebel
<h.go...@crazy-compilers.com> wrote:
>
> Hi,
>
> I wold like to list the newest 5 blog-posts in a side-column on every
> page. Can I use sort-codes in templates?
>
> What is the best way to do this?
>
> (I'm aware that this most probably will lead to a full rebuild when
> adding posts.)

Nikola explicitly does not support anything that would cause full
rebuilds to occur often, so the inclusion of the sidebar would happen
outside of Nikola. You could use something like the sidebar plugin
[0], and then include it in your pages via server-side includes or
front-end JavaScript.

[0]: https://plugins.getnikola.com/v7/sidebar/
--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16

Hartmut Goebel

unread,
Apr 4, 2023, 11:02:53 AM4/4/23
to nikola-...@googlegroups.com
Hi Chris,

> Nikola explicitly does not support anything that would cause full
> rebuilds to occur often, so the inclusion of the sidebar would happen
> outside of Nikola. You could use something like the sidebar plugin
> [0], and then include it in your pages via server-side includes or
> front-end JavaScript.

I fully agree that a full rebuild is to be avoided and appreiciate
nikola is working hard in this.

Anyhow, relying on Javascript for fetching relevant content is not an
option for me. Given that my blog changes very rarely (about 5 time a
year), a full rebuild is acceptable for me and the smaller restriction.

Thanks for pointing to the sidebar plugin. Anyhow using also leads to a
full rebuild whenever a blog post is added - except that anther tool is
required for completing the task and "nikola deploy" can't be used
anymore. I rather prefer building this into nikola (not into the core,
of course).


A quite different approach could be to create mini-HTML-pages to be
included as iframe? WDYT? How could this be done?

Roberto Alsina

unread,
Apr 4, 2023, 11:28:12 AM4/4/23
to nikola-...@googlegroups.com
If you really really really want to do this:

In conf.py you can write a function that generates the list of the last 5 posts and expose it as a member of GLOBAL_CONTEXT

That will make it available in templates.

Of course from them on you have to always use "nikola build -a" but that should work.


--
You received this message because you are subscribed to the Google Groups "nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nikola-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nikola-discuss/5ee15317-c076-187c-cd82-2ad51f485747%40crazy-compilers.com.

Roberto Alsina

unread,
Apr 4, 2023, 11:38:56 AM4/4/23
to nikola-...@googlegroups.com
On Tue, Apr 4, 2023 at 12:27 PM Roberto Alsina <ral...@kde.org> wrote:
If you really really really want to do this:

In conf.py you can write a function that generates the list of the last 5 posts and expose it as a member of GLOBAL_CONTEXT


This may not be as easy as I remembered it being. I'll try to write an example later.
Reply all
Reply to author
Forward
0 new messages