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

Override Block in Page

Started by Muut Archive 11 years ago · 4 replies · 684 views
11 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.

11 years ago

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

11 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 1326 9 years ago
Archive · by Muut Archive, 9 years ago
2 920 9 years ago
Archive · by Muut Archive, 9 years ago
2 4050 9 years ago
Archive · by Muut Archive, 9 years ago
1 2928 9 years ago
Archive · by Muut Archive, 9 years ago
3 1107 9 years ago