How to customize templates in minor ways without creating custom theme?

39 views
Skip to first unread message

Achab Bachadiensis

unread,
Nov 4, 2016, 9:58:07 AM11/4/16
to nikola-discuss
Hi there,

I would like to change the way available languages of a post are displayed (show flags instead of the visually disturbing "Also available in: ..." at the top) in a multilingual site. This fragment is generated from the html_translations(post) function (defined in data/themes/base/templates/post_header.tmpl).

Is there a way to override/redefine only this single function by including an extra template file (or something similarly simple), without creating a new child theme? I would like to keep the possibility of using any of the themes available while developing the site, just modifying this bit.

Thanks!

Roberto Alsina

unread,
Nov 4, 2016, 10:22:45 AM11/4/16
to nikola-discuss
The simplest way is to do this:
nikola theme -c post_header.tmpl
That will give you a copy of that template in templates/ edit at will, and that's it :-)

--
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.
For more options, visit https://groups.google.com/d/optout.

Achab Bachadiensis

unread,
Nov 4, 2016, 12:58:17 PM11/4/16
to nikola-discuss, ral...@kde.org

The simplest way is to do this:
nikola theme -c post_header.tmpl
That will give you a copy of that template in templates/ edit at will, and that's it :-)
Thanks! I assume I can change the "real" theme I use just by putting it in themes/custom/parent, right?

Now how do I override only some functions? At the moment, I have to keep the whole of post_header.tmpl in place, otherwise I get complaints (errors, that is). Any easy way to have all the functions I redefine in one place, conveniently?

Roberto Alsina

unread,
Nov 4, 2016, 1:04:28 PM11/4/16
to nikola-...@googlegroups.com
On Fri, Nov 4, 2016 at 1:58 PM Achab Bachadiensis <oty...@gmail.com> wrote:

The simplest way is to do this:
nikola theme -c post_header.tmpl
That will give you a copy of that template in templates/ edit at will, and that's it :-)
Thanks! I assume I can change the "real" theme I use just by putting it in themes/custom/parent, right?



Yes, but the end result is exactly the same.

 
Now how do I override only some functions? At the moment, I have to keep the whole of post_header.tmpl in place, otherwise I get complaints (errors, that is). Any easy way to have all the functions I redefine in one place, conveniently?

Sadly, that's not possible at this point.
I once embarked on a quest to make it easy but could not make it work properly.

I would say:

* Create a separate file with only your version of  the functions you want to override
* Copy the theme template like described before
* Edit the copied template, delete the functions you changed and import / inherit / something your template with the new functions

Achab Bachadiensis

unread,
Nov 4, 2016, 4:04:08 PM11/4/16
to nikola-discuss, ral...@kde.org
Thanks. I now have a copy of base_helper.tmpl and base_header.tmpl in my custom theme. The downside is obviously that if the parent template is updated in nikola, old (even those unrelated to my changes) from those overridden files will be used.

You mention I should keep only functions I need, but I don't see how I can make the parent template actually load my stuff without editing it. Maybe copy the original to something like base_helper_orig.tmpl and then create base_helper.tmpl with only functions changed and doing something like <%namespace name="???" file="base_helper_orig.tmpl" import="*">? Just guessing what it would look like.
Reply all
Reply to author
Forward
0 new messages