Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Override Block in Page

Started by Muut Archive 12 years ago · 4 replies · 804 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 Deleted User, 9 years ago
0 2612 9 years ago
Archive · by Muut Archive, 9 years ago
2 1722 9 years ago
Archive · by Muut Archive, 9 years ago
2 5018 9 years ago
Archive · by Muut Archive, 9 years ago
1 3848 9 years ago
Archive · by Muut Archive, 9 years ago
3 1823 9 years ago