Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Override Block in Page

Started by Muut Archive 12 years ago · 4 replies · 869 views
12 years ago

Hi@all,
is it possible to override (or extend) an existing block which is defined in a template?

I want to include a special JS-file on a specific page. So I tried to "override" the javascrips block which is defined in "base.html.twig".

TWIG
{% block javascrips %}
    {# Google Maps #}
    {% do assets.add('//maps.googleapis.com/maps/api/js?sensor=false') %}
{% endblock %}

but it doesn't work.

12 years ago

Btw you have a typo. Should be {% block javascripts %}

12 years ago

thx for your fast respone,

I already tried to use the parent function:

TWIG
{% block javascripts %}
    {# Google Maps #}
    {% do assets.add('//maps.googleapis.com/maps/api/js?sensor=false') %}

    {{ parent() }}
{% endblock %}

but then I get the following error message:

TXT

Calling "parent" on a template that does not extend nor "use" another template is forbidden in "@Page:/is/htdocs/***/***/***/user/pages/02.kanzlei/03.kontakt" at line 5
---

Suggested topics

Topic Participants Replies Views Activity
Archive · by Muut Archive, 10 years ago
1 672 1 week ago
Archive · by Deleted User, 9 years ago
0 3043 9 years ago
Archive · by Muut Archive, 9 years ago
2 1983 9 years ago
Archive · by Muut Archive, 9 years ago
2 5336 9 years ago
Archive · by Muut Archive, 9 years ago
1 4134 9 years ago