jared-shepherd of Nullera
7/18/2019 - 2:48 AM

Stencil - Get URL Parameters

{{!-- Get the currency object --}}
{{#withFirst currency_selector.currencies}} 
    {{!-- Get the start of the URL without the query string--}}
    {{#withLast (split this.switch_url "?")}}
      {{!-- Get the URL parameters, loop through them --}}
      {{#each (split this "&")}}
      
        {{!-- Parameter Name --}}
        {{first (split this "=")}}
        {{!-- Parameter Value --}}
        {{last (split this "=")}}
        
        {{!-- Example of checking a certain parameter + value --}}
        {{#if (first (split this "=")) '==' '<parameter-name-goes-here>'}}
        
          {{#if (last (split this "=")) '==' '<parameter-value-to-test-goes-here>'}}
            <span>Hooray for {{first (split this "=")}}</span>
          {{else}}
            <span>{{last (split this "=")}} is not the value you're looking for.</span>
          {{/if}}
          
        {{else}}
          <span>{{first (split this "=")}} is not the parameter you're looking for</span>
        {{/if}}
 
      {{/each}}
    {{/withLast}}
{{/withFirst}}