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
WIP Idea to avoid repeating ourselves so much in templates #2025
Conversation
Maybe there was some special styling that is now missing? |
@Kwpolska yes, probably. If we decide this line of work is worth pursuing, I will surely fix that. |
Apparently this will not work properly outside Mako and/or making it work right with Mako and Jinja means poking most of the templates in complex ways. |
Oh, well, it works for def-heavy templates, that's much more than nothing :-) |
What do you mean "def-heavy"? Would this be more useful if there were more defs in the base theme? I'm kind of planning of making more defs in the base theme, if that makes a difference. In a few weeks time, most likely. Testing out some stuff with my own site and thought I'd clean it up and introduce |
@Aeyoun for files that are a bunch of defs this is very useful (see the change in nikola/data/themes/bootstrap3/templates/base_helper.tmpl), basically, only have to keep the functions you change, the rest will be "inherited". For blocks, that doesn't work, so this technique doesn't help avoid repetition (fairly: it works in Mako, doesn't work in Jinja). So, the more templates we have that are collections of defs, the more this avoids stupid repetition. |
Avoid repeating ourselves so much in templates
inherits parent-theme/templates/whatever.tmpl
inwhatever.tmpl
This branch shows the simplified base_helper.tmpl in bootstrap3
You only have to do the silly redefinition-calling-parent for functions that are called from within that same file.
Problems:
jinjify needs to catch the reference to parent theme "base/" in this case and patch it to "base-jinja/"In internationalized sites the link to the translations is styled wrong, no idea whyLooks like I have run into something where mako is just too different from jinja to make jinjify work :-(
There seems to be no way to make this work in Jinja2, because blocks are not callable!
So, this means we should use macros instead of blocks, which means defs instead of blocks in Mako. May still be worth doing...