Blocks do not have paths so how can I pass a context to the block to get the correct results for a page?
A views page can read the url and use a path for the page to read a taxonomy term input for a contextual filter. A URL such as
example.com/a/term/b would be read by the view page with a path of
a/%/b. The value for the
% in the URL is passed in to the contextual filter to determine what content to include in the view.
Since a block doesn’t possess a path it is necessary to do a bit more configuration to achieve the result. To do so:
- Click on the contextual filter on the block view form in views.
When the filter value is NOT availableselect
Provide default value.
If the page in the path is a taxonomy term try this step 3 and 4:
Taxonomy term ID from URLfrom the Type drop-down box.
Load default filter from term page.
Or otherwise try this:
Raw value from URL
- Identify which part of the URL is the term. eg. for
A/term/Bthe term is in the second position.
When the filter value IS in the URL or a default is providedcheck "Specify Validation criteria"
Taxonomy termand the specific vocabulary being used.
Filter Value typepick term name converted to term ID"
Transform dashes in URL to spaces in term name filter valueswill ensure that any auto generated path alias' that have converted spaces to dashes are properly handled. Try your view with this checked and unchecked.
If your view is not appearing on the page troubleshooting steps should include verifying that the view works by testing input in the view preview. Make certain that any spaces are handled to match up with the setting in step 8. Also make certain that your view block is exposed in
If you want to select according to a Content Type instead of taxonomy, you need a different setup. Try the following:
- Click on Contextual Filters
- Add Content: NID On the WHEN THE FILTER VALUE IS NOT AVAILABLE section, select Provide default value and choose Content ID from URL on the dropdown list.
- On the WHEN THE FILTER VALUE IS AVAILABLE OR A DEFAULT IS PROVIDED section, select Specify validation criteria, choose Content on the VALIDATOR select box, and choose which Content Types you authorize to be displayed.
That should do it.