Is there a way to get the parameters from the referrer url?
I've tried this:
{{ craft.request.urlReferrer.getQuery }}
but that’s not working.
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityIs there a way to get the parameters from the referrer url?
I've tried this:
{{ craft.request.urlReferrer.getQuery }}
but that’s not working.
It can be done with some Twig code:
{% set referrer = craft.request.urlReferrer %}
{% if referrer %}
{# Remove everything before the `?` #}
{% set queryString = referrer|replace('/^.*\\?/', '') %}
{# Split the query string into individual params #}
{% set params = queryString|split('&') %}
{% for param in params %}
{# Split this param on the `=` sign #}
{% set parts = param|split('=') %}
{% set name = parts[0] %}
{% set value = parts[1] is defined ? parts[1] %}
{# Do something with it... #}
{% endfor %}
{% endif %}
Note that this could would require Craft 2.2 or later, which comes with a regex-enabled replace filter.