I need a variant in Panels' selection rule of "String: URL path" to be related to the the query string of the URL:

Variant 1 - String: URL path = mypath/page?querystring=1

Variant 2 - String: URL path = mypath/page?querystring=2

Surprisingly I can't find a solution for this!


You can accomplish using query strings in panels if you use php code for your selection criteria.

Something along the lines of

$url_comp = explode('/', request_uri());
$desired = $url_comp[2];
if ($desired == "page?querystring=1") {
return true;

will provide you with the access check on whether or not to show the panel variant. Check_plain may be called incorrectly in the code above but including some sort of check to make sure your querystring is clean would be very advantageous to prevent any sort of security issue.

You may need to adjust the position of your desired path above. url_comp[0] will return empty, url_comp[1] from your example above would return mypath and url_comp[2] would be page?querystring=1

I came up with the idea for this approach from the comments on https://api.drupal.org/comment/18449#comment-18449

  • Is this doable without PHP code? – wizonesolutions Apr 29 '14 at 12:55
  • 1
    Using php fields is executing php that is in the database and this is dangerous because it's very hard to debug – wranvaud Jan 19 '18 at 14:02

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.