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 →

Including assets per page

Started by Muut Archive 11 years ago · 1 replies · 768 views
11 years ago

Hi Everybody,
As in base.html.twig we add javascript assets like {% do assets.addJs('theme://js/something.js') %} can we include it in modular.html.twig. We have modular design, and we need the assets to load only if the modular page is been used.

Thanks in advance

11 years ago

sure you can include it in modular. Assuming your base has has a structure like this:

TWIG
    {% block javascripts %}
        {% do assets.add('jquery',102) %}
        {% do assets.addJs('theme://js/modernizr.custom.05229.js',101) %}
        {% do assets.addJs('theme://js/theme.js') %}
    {% endblock %}
    {{ assets.js() }}

You can override the javascript block, then call parent() to include the base stuff already defined, then add your own. Like this:

TWIG
{% block javascripts %}
    {{ parent() }}
    {% do assets.add('theme://js/modular-only.js') %}
{% endblock %}

Of course, your modular twig page must be extending the base that has the javascript block defined.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Muut Archive, 10 years ago
1 673 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