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
Add THEME_TEMPLATE_OVERRIDES. Refs #2021 #2072
Conversation
Continuation of #2026. I slipped up and closed that PR accidentally. Ties in with getpelican/pelican-themes#466. |
Doesn't this make Also, IMO, the docs for this should go to the |
Might deprecate
Maybe? I figured since it is one replacing or enhancing I'm amenable on either of these. |
Deprecating The reason I say, doc should go to [*]: Why is |
Noted... I should be able to get to updating the PR next week... Thanks! |
All set @avaris. |
This looks all good to me. I'm in favor of merging it. Any other thoughts? |
@almet Is the discussion of child themes separate from this, or does this PR obsolete that discussion? In my mind a simple override, while useful, is not the same as being to inherit from and |
@ssteinerx,
|
@digitalrounin I agree, and vote to merge this to allow overriding parts of a template completely while we workout/bike shed #1092. |
Lets summon @avaris on this one :-) any feedback ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry. I thought I had approved this. Apparently I forgot. Good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have several issues with this pr as shown in the review comments.
Additionally:
- Why the effort of introducing a new setting instead of just moving the existing EXTRA_TEMPLATES_PATHS to where you now introduced _OVERRIDES?
- You deprecate EXTRA_TEMPLATES_PATHS but not really because you don't do anything with it. Either move stuff from the old setting to the new one or don't deprecate.
pelican/tests/test_generators.py
Outdated
def test_theme_overrides(self): | ||
""" | ||
Test that the THEME_TEMPLATE_OVERRIDES configuration setting is | ||
being utilized correctly the Generator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utilized correctly in the Generator
docs/settings.rst
Outdated
A list of paths you want Jinja2 to search for templates. Can be used to | ||
separate templates from the theme. Example: projects, resume, profile ... | ||
These templates need to use ``DIRECT_TEMPLATES`` setting. | ||
``EXTRA_TEMPLATES_PATHS`` is being depricated, use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there no sphinx/rst directive to better emphasize deprecation?
pelican/generators.py
Outdated
@@ -52,6 +52,7 @@ def __init__(self, context, settings, path, theme, output_path, | |||
# templates cache | |||
self._templates = {} | |||
self._templates_path = [] | |||
self._templates_path += self.settings['THEME_TEMPLATE_OVERRIDES'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._templates_path = []
self._templates_path += self.settings['THEME_TEMPLATE_OVERRIDES']
is equal to
self._templates_path = self.settings['THEME_TEMPLATE_OVERRIDES']
pelican/settings.py
Outdated
@@ -97,6 +97,7 @@ def load_source(name, path): | |||
'RELATIVE_URLS': False, | |||
'DEFAULT_LANG': 'en', | |||
'DIRECT_TEMPLATES': ['index', 'tags', 'categories', 'authors', 'archives'], | |||
'THEME_TEMPLATE_OVERRIDES': [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use theme_templates internally, might want to change it for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do have to un-approve this (thanks to @ingwinlu for pointing out).
I don't like the way deprecation handled here.
Either the old setting is gone and replaced with the new one:
- remove
EXTRA_TEMPLATES_PATHS
from the docs. - show a warning if the old one is present in the settings and move the values to the new setting.
- it won't be used anymore (i.e. no more
self._templates_path += self.settings['EXTRA_TEMPLATES_PATHS']
).
or we reuse the old setting with new functionality (as @ingwinlu suggested)
My reading is that I find this really confusing but I also never used I thought the point of this PR was to add a setting to allow overriding templates not used in |
Current doc for The only difference between |
If I'm reading this right, you can set the theme, then use EXTRA_TEMPLATES_PATHS instead of the the proposed PR and it's just a documentation issue. |
No...
Jinja will look through these in this order and return the first matching template it finds. So, with This PR adds the new setting to the top of the chain, so if the template that's being searched is there, it'll be used (instead of the one from the theme). That being said, there is also a documentation issue with |
By the way, it might be worth to include the current theme as a {% extends '!theme/article.html' %}
{% block someblock %}
My override
{% endblock %} |
@avaris So, if you put your parent theme in EXTRA_TEMPLATES_PATHS, and your "child template" as the regular theme, you accomplish the same thing with no code changes? |
A theme is more than just the templates. You'd need to duplicate the static part (CSS, JS, etc) of the "parent theme" in your "child theme" which is no better than copying the theme, modifying whatever you want and using it as |
@avaris Yes, I suspected that the other chunks 'wouldn't come along for the ride.' Since I hadn't looked at |
I wonder how traumatic it would be to just add inheritance of the CSS/JS etc. from My guess is that I also agree that adding the PrefixLoader ability would make it hard to really come up with more to add for true "child themes." |
Real theme inheritance is required if the child theme contains its own static content (e.g. customized main CSS). It could still be possible with certain settings config, but would certainly be "hacky". For template-only modifications, this PR should be sufficient. |
@ingwinlu - Good stuff... Keep it coming... I just submitted a new round of changes. Let me know if I missed, or misinterpreted, anything. @avaris - Good idea on @ssteinerx - Actually, anyone that wants to add custom pages via If someone whats to go in and add their own static content (images, JS, CSS) In my mind, Pelican users can wear one of two hats:
A person can where one, or both. I view settings such as
|
I love where this is going. Simplicity matters :-) |
@almet, @ingwinlu, @avaris, @ssteinerx, |
@digitalrounin for testing it, you can create an override, create appropriate settings, create a generator and use its |
Allow for overriding individual templates from the theme by configuring the Jinja2 `Environment` loader to search for templates in the `THEME_TEMPLATES_OVERRIDES` path before the theme's `templates/` directory.
Any last thoughts from @getpelican/reviewers? Your input would be greatly appreciated! |
Any chance to move this forward? |
@avaris: Any chance you could take another look and see if anything else is required before merging? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. Looks good for me 👍
Many thanks to @digitalrounin for the contribution and to everyone who helped review it! |
Thanks Everyone! |
Allow for overriding individual templates from the theme by configuring
the Jinja2
Environment
loader to search for templates in theTHEME_TEMPLATE_OVERRIDES
path before the theme'stemplates/
directory.