Is it possible to determine whether or not a query string has a param with no value. For example


Technically that's a valid url but the craft.request object doesn't appear to have a way to see that. craft.request.getParam('myparam') returns nothing as does craft.request.getQuery('myparam'). I have tried using an explicit test for 'true' and 'false' but no luck.

Right now I'm grabbing the entire query string value and then using the 'in' to find the param name but thats pretty fragile is another param or value contains the same string.

2 Answers 2


A parameter with no value set returns an empty string '' for craft.request.getParam(). But if the whole parameter is not included at all, it returns null.

This means you can test for null (→ see Twig docs) like so:

{% if craft.request.getParam('myparam') is not null %}
    My Parameter is included in the query string!
{% endif %}

You can use the defaultValue to determine if the value is there or not.

{% if craft.request.getParam('myVar', -1) != -1 %}
  myVar is here!
{% else %}
  myVar is missing...
{% endif %}

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.