<p>Use <a href="http://buildwithcraft.com/docs/templating/craft.request#getQueryStringWithoutPath" rel="nofollow">craft.request.getQueryStringWithoutPath()</a> like so:</p>

<pre><code>products/category?{{craft.request.getQueryStringWithoutPath()}}
</code></pre>

<blockquote>
  <p>Returns the query string, except for the <code>p=</code> param (which was probably added by your .htaccess redirect).</p>
</blockquote>

<p>More complicated logic to avoid the <strong>?</strong> when the query string is empty (one of several ways to do this):</p>

<pre><code>{# queryString will include '?' if we have one, otherwise '' #}
{% set queryString = (craft.request.getQueryStringWithoutPath() ? '?'~craft.request.getQueryStringWithoutPath()) %}
products/category{{queryString}}
</code></pre>

CC BY-SA 3.0
2015-03-20T18:12:55.087Z
But without query or param the URL's now have a "?" in it. Is it possible to conditionally hide or show the question mark depending if there is a query in the page url?
Johannes Lamers
CC BY-SA 3.0
2015-03-20T19:11:23.663Z
Johannes, try something like this: `{{ craft.request.getQueryStringWithoutPath() ? '?' ~ craft.request.getQueryStringWithoutPath() }}`, or better: assign the query to a var first.
carlcs
CC BY-SA 3.0
2015-03-20T19:14:17.340Z
@carlcs just beat me to it!
Marion Newlevant
CC BY-SA 3.0
2015-03-20T17:59:48.223Z
2015-03-20T19:13:55.633Z
2015-03-20T19:13:55.633Z
Marion Newlevant
<p>I'm trying to grab the query or param from an URL and then add it to an URL.</p>

<p>like products?price=15</p>

<p>How can I add the ?price=15 to a URL?</p>

<p>Like products/category?price=15?</p>

<queries><params>
How to get query or param from URL and then use in Links?
# How to get query or param from URL and then use in Links?

(Asked by: username_0 on 2015-03-20)

I'm trying to grab the query or param from an URL and then add it to an URL.

like products?price=15

How can I add the ?price=15 to a URL?

Like products/category?price=15?

**Tags:** queries, params


---

## 1 answers

### Answer by username_1 on 2015-03-20. Score: 6 | Accepted answer

Use craft.request.getQueryStringWithoutPath() like so:
products/category?{{craft.request.getQueryStringWithoutPath()}}


Returns the query string, except for the p= param (which was probably added by your .htaccess redirect).

More complicated logic to avoid the ? when the query string is empty (one of several ways to do this):
{# queryString will include '?' if we have one, otherwise '' #}
{% set queryString = (craft.request.getQueryStringWithoutPath() ? '?'~craft.request.getQueryStringWithoutPath()) %}
products/category{{queryString}}

> **Comments:**
> **username_0**: But without query or param the URL's now have a "?" in it. Is it possible to conditionally hide or show the question mark depending if there is a query in the page url?  
> **username_2**: Johannes, try something like this: `{{ craft.request.getQueryStringWithoutPath() ? '?' ~ craft.request.getQueryStringWithoutPath() }}`, or better: assign the query to a var first.  
> **username_1**: @username_2 just beat me to it!  

---

