Drupal - Drupal 7 Contextual Filter on URL Alias

I think the simpliest way is to use Panels, and override the Node page. Add a variant and put your view in it, and send the node's nid argument to it, using node:nid contextual argument.

  1. (install page manager)
  2. Enable node view page (node/%node)
  3. Add a variant, set a validation criteria selecting your concerned node type
  4. Use simple one-column display
  5. Add your view in your column
  6. It asks for an argument, send the node:nid, (or entity_id, or whatever)Send your node's nid to your view
  7. In your view, use node:nid contextual filterYour view arg

All is done.


Set path alias for the content type to something like articles/[node:title]

Option 1: using views to run detail pages

In views:

  1. Create a Page view with the path set to the /articles/%
  2. Add Contextual filters Content: Nid and set it to the following:

    • When the filter value is NOT in the URL => Provide default value
    • Type => Raw value from URL
    • Path => Component 1 (Check "use path alias")

This does a path lookup on the last url segment (something like "my-article-title-path-alias") and returns the correct node ID.

Option 2: By-pass views to run detail pages

Instead of setting the path as /articles/% simply set it as /articles and let the all the path aliased /articles/% nodes resolve normally.

Tags:

Views

7