<p>It can be done with some Twig code:</p>

<pre class="lang-twig prettyprint-override"><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('&amp;') %}

    {% 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 %}
</code></pre>

<p>Note that this could would require Craft 2.2 or later, which comes with a regex-enabled <a href="http://buildwithcraft.com/docs/templating/filters#replace" rel="nofollow">replace</a> filter.</p>

CC BY-SA 3.0
2014-09-12T13:43:25.843Z
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
CC BY-SA 3.0
2014-09-12T16:27:23.357Z
@Katrin The regex bit wasn’t totally necessary, just saved a couple additional lines of code :)
Brandon Kelly
CC BY-SA 3.0
2014-09-11T17:15:25.820Z
2014-09-12T16:26:43.230Z
2014-09-12T16:26:43.230Z
Brandon Kelly
<p>Is there a way to get the parameters from the referrer url?</p>

<p>I've tried this:
<code>{{ craft.request.urlReferrer.getQuery }}</code>
but that’s not working.</p>

<url><request>
Get parameters from referrer
# Get parameters from referrer

(Asked by: username_0 on 2014-09-11)

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.

**Tags:** url, request


---

## 1 answers

### Answer by username_1 on 2014-09-11. Score: 4 | Accepted answer

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.

> **Comments:**
> **username_0**: 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!  
> **username_1**: @username_0 The regex bit wasn’t totally necessary, just saved a couple additional lines of code :)  

---

