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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

JS snippets at very end of body (GRAV captcha)

Started by Genbrua 9 years ago · 2 replies · 909 views
9 years ago

Is it possible to add JS snippets to the end of the body from within a partial or modular? GRAV's captcha field places a jQuery snippet in the middle of the page, which forces me to load my jQuery file in the head. Which is a waste, because I don't really need it in the head otherwise, so I'd like to add the captcha snippet to the very end of the body, below the jQuery file.
I can think of several instances where the feature would be handy, but if it exists, I can't find it.

9 years ago

Module code:

TWIG
{% block bottom %}
    {% do assets.addCss('theme://src/node_modules/slick-carousel/slick/slick.css', {'group':'bottom'}) %}
    {% do assets.addCss('theme://src/node_modules/slick-carousel/slick/slick-theme.css', {'group':'bottom'}) %}

    {% do assets.addJs('theme://src/node_modules/slick-carousel/slick/slick.min.js', {'group':'bottom'}) %}
    {% do assets.addJs('theme://js/slider.js', {'loading': 'inline', 'group':'bottom'}) %}
{% endblock %}

This implies having this in base.html.twig (whatever your base template partial is named...):

TWIG
{% block bottom %}
    {{ assets.css('bottom') }}

    {{ assets.js('bottom') }}
{% endblock %}
9 years ago

That's not what I mean...

When you use the Captcha field from the GRAV form plugin, it places a little bit of jQuery in your form, to help validate your form. But this means that, unless I load the jQuery at the top of the page, the form breaks because that validation snippet needs jQuery in order to work. I want the ability to move that GRAV-generated snippet, and any other snippets I may write myself, to the very bottom of the page, right before the closing body tag, so both the jQuery library and any and all javascript snippets - together- are at the bottom of the page and don't slow down the page loading.

These snippets aren't separate files and, because I expect a few of them to be content-based generated, I can't always make workarounds to force them into being separate files either. Simply put, the ability to add on-the-fly javascript snippets to the bottom of the page is a feature I, and I believe many others, would benefit from.

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 56 13 hours ago
Support · by Anna, 3 days ago
2 61 16 hours ago
Support · by Justin Young, 17 hours ago
1 32 17 hours ago
Support · by Duc , 1 week ago
2 66 5 days ago
Support · by Colin Hume, 1 week ago
2 59 5 days ago