Register theme prefixes as namespaces in twig #2210
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When creating a theme that inherit from another theme one common thing is that you want to change a tiny thing in an existing twig file.
I couldn't find a good way to do that without copy the whole twig-file over to my theme. Which means that if the base theme update that twig-file I will never get the changes. And I couldn't figure out a way to reference the base theme twig file and override it at the same time.
So with this change I can change my theme config to something like this:
And then if I want to update the footer in base.html.twig I can just create a base.html.twig file in mytheme that looks something like this:
When I first implemented it I just had one foreach that handled the empty prefix also. But because when
$this->grav->fireEvent('onTwigTemplatePaths');
some stuff goes in and touches$this->twig_paths
that didn't work.