18

I want to pass some values to my view via contextual filters in the URL. What GET naImes do I use? There seem to be no clue given, just this "The contextual filter values is provided by the URL".

If I have to construct that URL, how do I find out what GET var names do I need to pass so they are recognized?

3 Answers 3

13

Contextual filters aren't passed in separate variables, they are part of the path. If your view path is xxx/yyy then to have a filter value of nn the path would be xxx/yyy/nn.

1
  • 1
    +1. and this xxx/yyy order is the same as you can see under "Contextual filters" pane in the Views UI.
    – AKS
    Mar 14, 2013 at 17:05
12

Use Provide default value in the contextual filter.

contextual filter

also you can use php code for getting the value from url

enter image description here

4
  • 1
    Do you have some example of the PHP code one could use? Thanks!
    – petergus
    Aug 27, 2014 at 14:29
  • It's related to that field. For example:- Is this a number field then -- return 1; or return $user->uid; etc..... will work.
    – Sibiraj PR
    Sep 12, 2014 at 4:08
  • Arent these options for when the value is not in the url? How will it gauge its a value sent as a parameter?
    – pal4life
    Oct 2, 2014 at 1:29
  • 1
    It is never a good practise to have PHP code in your database, always do your code in files and save them in a code revision system
    – lslinnet
    Aug 3, 2015 at 19:07
6

If you want to pass arguments via GET in the URL you can use BEF module for this.

For example: mydomain.com/your-view-path?field_a=valuea&field_b=valueb

With Better Exposed Filters you need to add exposed filters (not contextual filter), check the expose this filter option and the GET variable name is below in more options. Then if you don't want to show the filter you can hide it in Better Exposed Filters Settings.

Don’t forget to enable Use Ajax option if your view is a block display.

The exposed filter style setting must be set on Better Exposed Filters instead of Basic.

It is very useful with view blocks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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