Hi,
by default file “default.html.twig” is extended with “base.html.twig”
I created new template: “products-home.html.twig” with the same content as “default.html.twig”. I want “products-home.html.twig” to be extended with modified copy of “base.html.twig” called: “base-modified.html.twig”.
Unfortunately it is not working. File with template “products-home” is still extended with “base.html.twig”, not the modified version called: “base-modified.html.twig”.
Check this recipe on how to extend base template itself. I think this might give you an idea on how to approach the issue
@mkukulka,
Since you are working with ‘modified copies’, the following steps are tested and should work:
- Using fresh copy of Grav 1.7.3, with theme Quark
- Create an inherited theme. If not, all changes will be lost when a new version of Quark arives.
Use the following command to create an inherited theme
$ bin/plugin devtools new-plugin
and inherit from ‘Quark’.
Let’s name the new theme 'mytheme’
- Tell Grav to use the new theme in ‘/user/config/system.yaml’:
pages:
theme: mytheme
- Copy ‘user/themes/quark/templates/default.html.twig’ to ‘user/themes/mytheme/templates/products-home.html.twig’
- Replace the content of ‘user/themes/mytheme/templates/products-home.html.twig’ with:
{% extends 'partials/base-modified.html.twig' %}
{% block content %}
<h4>This is from template '/mytheme/templates/products-home.html.twig'</h4>
{{ page.content|raw }}
{% endblock %}
- Copy ‘user/themes/quark/templates/partials/base.html.twig’ to ‘user/themes/mytheme/templates/partials/base-modified.html.twig’
- Make any change in ‘user/themes/mytheme/templates/partials/base-modified.html.twig’. For example on line 84:
<h4>This is from template '/mytheme/templates/partials/base-modified.html.twig'</h4>
{{ block('content_surround') }}
- Create page ‘user/pages/03.products/products-home.md’
- Browse to ‘/yoursite/products’
- You should see something like:
Note: