As we all familiar with the basics of normal filter and contextual filter. In this tutorial i won’t touch basics of views but The Contextual filter.

If you’re not familiar with Views Contextual Filters, It’s also known as Views Arguments in Drupal 6 and then got renamed for Drupal 7 as well. Essentially, Contextual Filters intelligently filters content to reduce the result set in various ways and is pretty powerful.It makes your View scalable and one View can be used on many pages on your site rather than having to create many views, one for each page / block.

Lets’ Begin with Contextual Filter

Example of Books, my use case is something like this: I have a node type "Books" with some additional field (Title/ Authored by). The view example.com/basics/ lists all content belongs to specific user id and by adding a contextual filter I can filter the View to books relevant to a particular uid

i.e:  example.com/basics/ etc

Step 1:  Under the "Advanced" area of the Views UI admin, expand that and you will see "Contextual Filters".

Advanced Filter

Step 2: We are going to add “Content Authored By”  & click on Apply (all displays)

Content Authored by

Step 3: Select Provide default value under Default actions “Type: Raw value from URL” WHEN THE FILTER VALUE IS NOT IN THE URL
below you will get the Path component. so, based on your requirement you can set the path component. for now i’m keeping default path to 1 and click on Apply (all displays)

THE FILTER VALUE IS NOT IN THE URL

Step 4:  Click on Save button and save the view page configuration. now you can visit the page example.com/basics/.

Now Keep changing the available uid to load the page based on their user id.

save view page configuration

E.g: with uid 3

UID 3

E.g: with uid 4

UID 4

Jaywant Topno

Jaywant is associated with Valuebound from past few years. Joined as a Trainee to get engaged with development ops and Drupal Community. Currently he is helping a Content delivery Team to produce a valuable information and newbies to understand Drupal. If you really want to hang around join him on CALL of DUTY, i believe you'll get a perfect head shot.
More about Jaywant Topno

comments powered by Disqus