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

Inherited theme : make it possible to customize specific blocks from base.html.twig #95

Closed
aoloe opened this issue Feb 9, 2019 · 8 comments
Labels

Comments

@aoloe
Copy link

aoloe commented Feb 9, 2019

When building a theme that inherits Quark, I think there's no clean way to customise a specific block of the base template.

This is also an issue with Antimatter.

Somebody opened a ticket for Antimatter:

getgrav/grav-theme-antimatter#97

and even made a pull request:

getgrav/grav-theme-antimatter#100

which has been left uncommented.

Please, refer to the original ticket for the reasons behind this request.

@luuuke
Copy link

luuuke commented Apr 2, 2020

I've stumbled over the same problem.

What I did to solve this problem cleanly is to explicitly add Quark as a twig namespace by using the theme's my-theme.php to listen on the onTwigLoader event and adding the Quark theme template directory.

My "my-theme" is set up using the devtools and inherits from the Quark theme. The contents of my-theme.php are as follows.

<?php
namespace Grav\Theme;

use Grav\Common\Grav;
use Grav\Common\Theme;

class MyTheme extends Quark {
    public static function getSubscribedEvents() {
        return [
            'onTwigLoader' => ['onTwigLoader', 10]
        ];
    }

    public function onTwigLoader() {
        parent::onTwigLoader();

        // add quark theme as namespace to twig
        $quark_path = Grav::instance()['locator']->findResource('themes://quark');
        $this->grav['twig']->addPath($quark_path . DIRECTORY_SEPARATOR . 'templates', 'quark');
    }
}

And when I want to overwrite a block in partials/base.html.twig I do the following:

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

{% block header %}
This is a shitty header now.
{% endblock %}

Quite a pleasure to be able to modify Gravs behavior so easily, major props to the developers.

@Karmalakas
Copy link

Just ran into the same issue. Thanks @luuuke

@rhukster
Copy link
Member

rhukster commented Jan 4, 2021

@luuuke 's solution is elegant. I recommend this approach!

@rhukster rhukster closed this as completed Jan 4, 2021
@Karmalakas
Copy link

Karmalakas commented Jan 4, 2021

This might be added to documentation. Maybe to cookbook section somewhere?

@rhukster
Copy link
Member

rhukster commented Jan 4, 2021

The docs are fully open to user submissions of this type. I would gladly accept a PR that provided this approach.

@aoloe
Copy link
Author

aoloe commented Jan 5, 2021

@rhukster i understand your position, but i don't feel like -- at this point -- closing this ticket was the right action.

indeed, one way to solve this ticket is to accept a PR that adds the snippet above to the docs.
but there is no such PR, so i consider that grav/quark still does not have an easy (or non trivial but documented) way to inherit block and the issue is still there.

please, consider reopening this ticket.

@Karmalakas
Copy link

Here you go :)

@aoloe
Copy link
Author

aoloe commented Jan 7, 2021

thanks @Karmalakas !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants