1

I am using Drupal 7.34. I have used Views module many time but I don't know difference between normal filter and contextual filter. So can you tell me What is the difference between normal filter and contextual filter in Views?

2

In simplified language to understand.

Normal Filter: Normal filter takes the fixed data from the available data. For example, you have created a views with Content: Title which will show all the title of nodes available on the site. But if you provide the Filter: Content type(Articles), then it will show only the Node title of Articles. Hence here filter, filters all data and gives only data which belong to Articles. So this is the Normal filter.

Contextual Filter: Now, Sometimes, you do not have the fixed filter value, suppose, Logged-in-user, value available in URL, Author name of currently loaded page. So, this kind of filter values are dynamic and keep changing, so Contextual filter provides the way to solve this. To visualize this you can see the following UI image of contextual filter. Which has mainly two section.

1. WHEN THE FILTER VALUE IS NOT AVAILABLE

2. WHEN THE FILTER VALUE IS AVAILABLE OR DEFAULT IS PROVIDED.

Now, in the first option WHEN THE FILTER VALUE IS NOT AVAILABLE itself defines what is Contextual filter is- So, Contextual filter SAYS to you, "I can fetch value from following listed areas(as you can see in image), you select from where shall I fetch. And I will take it as Filter value."

Example to understand Contextual filter: Now your site has the Taxonomy terms- BMW, AUDI, HONDA. So, in fixed value filter you can take only one value. But, what you will do when that value is keep on changing based on browsing.

So, suppose, I select contextual filter and select Taxonomy term ID from URL So, if URL will have BMW is will take BMW as filter, If URL will have AUDI it will take AUDI as filter value. So, filter value keep on changing here, hence Contextual filter provides the way for this.

enter image description here

0

I'm just quoting d.o. and accentuate:

Contextual filters work similarly to regular filters, but there is one important difference. Instead of setting a filter value manually, the value is fetched from variables sent programmatically to the view. A regular filter could give you all nodes written by a specified user. A contextual filter for a node author would be able to display all nodes written by the currently viewed user, or the same user who wrote the currently viewed node. The concept is that contextual filters prepare a view for filtering, but the filter value is not yet determined. When the view is eventually called, it is also provided with data used to complete the contextual filters.

Recommended further reading: Contextual Filters on d.o.

0

In short, both filter the data shown from the view, but a contextual filter filters the data basing on the values passed in the view's URL.
It is also true that it is possible to tell the view what to do when a value is not present in the URL (so that the view can handle two different URLs like blogs and blogs/%user), but this is essentially the difference between the two kind of view filters.

Also, normal filters can be exposed to the user, so that they can change the data shown in a view by changing the value of the filter. This cannot be done for contextual filters.

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.