It often happens, even deliberately, that views with contextual filters are called without the data to set the contextual filter values. This is particularly true for block displays, which without any paths don't have a natural way of receiving contextual filter values.

You can configure each contextual filter to set how the view should react if the filter value is missing. (See figure 10.8). The options are:

  • Display all results for the specified field: This will ignore the contextual filter all together.
  • Provide default value: This is used to fetch/create an artificial filter value, should a real one be missing.
  • Show ”Page not found”: This hides the view.
  • Display a summary: This alters the view, having it display a list of all filter values that would lead to results in the view, linked to the view with each contextual filter value present. The list may be configured in a number of ways, for example to display the number of results for each filter value or displaying a jump menu rather than an HTML list.
  • Display content of ”No results found”: This gives the same result as when the view has no results to display.

The functions for creating or fetching default values for contextual filters are used rather frequently, especially for block displays, and there are a numbers of options available to do this. These options may vary between different data fields, but the most common ones are:

  • Fixed value: This gives a static value, provided by you when the view is built.
  • Content ID from URL: This is used to fetch a node ID from the current path, assuming it contains a node ID.
  • PHP code: This allows a manually entered PHP script, with access to local data, to build a default filter value. Having PHP code in the configuration is bad for a number of reasons (such as security and performance), but it may be useful during prototyping.
  • Taxonomy Term ID from URL: This is used to fetch a term ID from the current path. You may optionally fetch term IDs from a currently viewed node and limit the terms to selected vocabularies.
  • User ID from URL: This is used to fetch a user ID from the current path and, optionally, the user ID for the author of the currently viewed node.
  • User ID from logged in user: This fetches the user ID from the active user.
  • For contextual filters for date and time fields there are some settings available to fetch current date and time, or time values from a currently viewed node.


Figure 10.8: A view may react in a number of different ways, if a value for a contextual filter is missing. Possible reactions include displaying a summary of possible filter values, or having the view generate a value by itself.

AttachmentSize
09.8 contextual filter missing.png55.69 KB

Comments

jorisx’s picture

Question: When i have selected the Content ID from URL
How would i get a default nid for my view when there is no node ID in the URL ?
So when I'm on search, taxonomy or user pages, I still want the view to display the content of node 1 in the view... !?