Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Easy Theme Development via Inheritance

Started by Muut Archive 12 years ago · 12 replies · 554 views
12 years ago

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!

12 years ago

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!

12 years ago

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.

12 years ago

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! :)

11 years ago

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?

11 years ago

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).

11 years ago

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.

11 years ago

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:

TWIG
{% 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.

10 years ago

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 %}
<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.

10 years ago

Now I copy over base.html.twig from antimatter. :-D
Thanks a lot!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1354 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4064 9 years ago
Archive · by Muut Archive, 9 years ago
1 2951 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago