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

Including assets per page

Started by Muut Archive 11 years ago · 1 replies · 543 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 Deleted User, 9 years ago
0 1338 9 years ago
Archive · by Muut Archive, 9 years ago
2 927 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2941 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago