New blog post that outlines the best strategy for theme development based on theme-inheritance or base-theme:
http://getgrav.org/blog/theme-development-with-inheritance
Cheers.
New blog post that outlines the best strategy for theme development based on theme-inheritance or base-theme:
http://getgrav.org/blog/theme-development-with-inheritance
Cheers.
Theme inheritance seems like a real good way to be sure new configuration options are reflected in custom themes. But I suspect that custom themes change enough about the Twig templates as to make their inheritance less valuable.
But that’s not always true, so we get many of the benefits of “child themes” without the pain!
You can also ‘theoretically’ create a uniquely named template in your theme: default2.htm.twig
, that simple extends the base theme’s default.html.twig
and in your unique template, you just override the one block
you wish to modify.
So you can actually do overrides of specific blocks sections of a twig template. Pretty powerful stuff!
Yes! I hadn’t thought of that, but Twig does give more power in templating than I’m used to. So there’s inheritance all the way down to the block level.
Yes and with Grav’s inheritance it will fall back through the streams to find the file to extend. Also Twig has a really powerful embed tag that is a combination of include and extend.
It takes a bit of time to get your head around it, but when you do, it will blow your mind!
Inheritance link bad. No search plugin installed or visible under blog. In-fact, as I read the forums, there are many bad links that reference posts or the Learn section. Where might I locate the Inheritance info?
Found it.
FYI … For those looking to use Inheritance WITH the new Admin Panel plugin, you need to be aware that you have to copy all the current .YAML files located in the root of the parent-theme’s “Template” folder. Otherwise, when you “add page” through the Admin plugin the correct Display Templates do not show (some will be missing).
Can confirm the point B.A. Umberger makes about having to copy the parent-theme’s “template” twig files to the inheritance (child) theme. Before I did this I only saw a couple of the templates, but not all.
One other follow up question about using the embed tag in Twig: how do I use it? For example I have an inheritance theme (called ronaldsmeets) that uses Antimatter as base theme.
Say I want to override the default footer located in user hemes\antimatter emplates\partials\base.html.twig.
If I make a Twig file: user hemes\ronaldsmeets emplates\partials\base.html.twig and add this:
{% embed 'user/themes/antimatter/templates/partials/base.html.twig' %}
{% block footer %}
<footer id="footer">
<p>New footer info</p>
</footer>
{% endblock %}
{% endembed %}
It won’t work: Runtime exception - Template “user/themes/antimatter/templates/partials/base.html.twig” is not defined ().
I have also tried variations on relative paths using (multiple) “…/”, but still no result.
Hi guys,
I have the same problem. Any ideas? Thanks a lot.
---------------------------------------------------------------------- -------------------------------------------------------------------```
One other follow up question about using the embed tag in Twig: how do I use it? ) For example I have an inheritance theme (called ronaldsmeets) that uses Antimatter as base theme.
Say I want to override the default footer located in user hemes\antimatter emplates\partials\base.html.twig.
If I make a Twig file: user hemes\ronaldsmeets emplates\partials\base.html.twig and add this:
{% embed ‘user/themes/antimatter/templates/partials/base.html.twig’ %}
{% block footer %}
New footer info
{% endblock %} {% endembed %}It won’t work: Runtime exception – Template “user/themes/antimatter/templates/partials/base.html.twig” is not defined ().
I have also tried variations on relative paths using (multiple) “…/”, but still no result.
I’m afraid I don’t know much about the embed plugin, it’s developed by a 3rd party. Try posting to the issue tracker: https://github.com/Gertt/grav-plugin-embed/issues
Now I copy over base.html.twig from antimatter.
Thanks a lot!