Martin Pešout
Martin Pešout

Reputation: 47

Accessing GET variables in Assemble.io

I'm creating webpage using Assemble.io templating system and Grunt. Is there any way how can I access GET variables inside my .hbs tempates? I need to create a simple condition:

{{#if debug}}
<script src="path_to_script">
{{/if}}

And call this condition only in case of GET param ?debug=1 after current URL. Is it possible to access GET variables from .hbs templates?

Upvotes: 1

Views: 79

Answers (1)

Konstantin Tarkus
Konstantin Tarkus

Reputation: 38358

This has nothing to do with static site generator, since query string's value is available only at runtime.

However you can include the following code snippet into your .html page:

<script>
if (window.location.search.substring(1).split('&').indexOf('debug') > -1) {
    var s = document.getElementsByTagName('script')[0],
        el = document.createElement('script');
    el.async = true;
    el.src = 'patth_to_script';
    s.parentNode.insertBefore(el, s);
}
</script>

And when you open it in a browser http://www.example.com/page?debug, the required script will be loaded along with other scripts referenced on the page.

Upvotes: 1

Related Questions