Drupal Contextual filters

Contextual filters are the Views mechanism for dynamically refining the contents of a view. It might be also called as "dynamic filters".  Contextual filters in the Views UI, and review the Taxonomy term view that comes with Drupal and how it uses a contextual filter.

For example
A contextual filter for a node author would be able to display all nodes written by the currently logged in user.

Step 1

We have to go through basic View Page creation by visiting /admin/structure/views/add

Fill up View Basic information, Page settings detail and click on Save and edit. 
I have created a view with below input.

View Basic Information
         View name: Article
         Description: listing article created by logged in User

View Settings
         Show: Content
         of Type: Article
         
Page Settings
        Page Title: Article
        Path: article

Page Display Settings
         Display format: Table


















Step 2
Once we have done with Step1, next we would be redirected to View Settings Page. Here I have added Body, Authored by & Authored on under Fields Section. Now click the Advanced Section on extreme right and click on CONTEXTUAL FILTERS “Add” button.

FIELDS
     Content: Body
     Content: Authored by (Authored by)
     Content: Authored on (Authored on)













Step 3

Search For “Authored by” and click on Apply (all displays).












Step 4
Select “Provide default value” under WHEN THE FILTER VALUE IS NOT IN THE URL & Select Type as “User ID from logged in user” and click on Apply (all displays).

Step 5
So, we are done with view creation. It’s time to review by visiting
the URL: localhost/d8/article

This page is showing articles created by logged in users and we don’t have to pass any additional argument. Try logging with some other user credentials and visit article-by-you page to test the view we have created just now. 


No comments:

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...