3

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.

4

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.

2
  • Awesome, thank you so much! Had an inkling that this would require some regex wizardry, that world does somewhat scare me though... Clever breadcrumbs here I come, woooooo! – Katrin Sep 12 '14 at 13:43
  • @Katrin The regex bit wasn’t totally necessary, just saved a couple additional lines of code :) – Brandon Kelly Sep 12 '14 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.