Skip to content
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

Register theme prefixes as namespaces in twig #2210

Merged
merged 1 commit into from
Nov 12, 2018

Conversation

WizKid
Copy link
Contributor

@WizKid WizKid commented Oct 4, 2018

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:

streams:
  schemes:
    theme:
      type: ReadOnlyStream
      prefixes:
        '':
          - user/themes/mytheme
          - user/themes/quark
        'quark/':
          - user/themes/quark

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:

{% extends '@quark/partials/base.html.twig' %}

{% block footer %}
    My footer text
{% endblock %}

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.

@rhukster
Copy link
Member

This look good to me, let me discuss with @mahagr though...

@rhukster rhukster requested a review from mahagr October 12, 2018 03:42
@WizKid
Copy link
Contributor Author

WizKid commented Oct 12, 2018

I mostly want some way to access the original template. Because that would make things so much easier. This was the easiest way I could figure out. So there may absolutely be some better way to do this.

Copy link
Member

@mahagr mahagr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good to me.

@rhukster rhukster merged commit d0b34d1 into getgrav:develop Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants