Can I use a node name in a path in a contextual filter?

2.1k Views Asked by At

I can create a view with path "/content/%/relatedarticles", and then create a contextual filter that limits nid to what's passed in "%" in the path. This means that if I go to drupalsite.com/content/1/relatedarticles, I can display all articles related to node 1. I've got this working just fine.

I don't like numbers in URLs, so I'm using aliases. If I have content at drupalsite.com/content/first-node, I want to be able to go to drupalsite.com/content/first-node/relatedarticles and get the same thing as above.

But I can't seem to make this work. The contextual filter validator seems to convert taxonomy terms to ids and user names to ids, but not content names.

Is there some way of making this work?

3

There are 3 best solutions below

0
On

You must set validation on to use the taxonomy term in the Contextual filer. Set the filter type to term name converted to tid and check the box Transform Dashes...

The dashes must be addressed to read multi-word URL path segments correctly.

0
On

For Drupal 6 use the Sub-path URL Aliases module, and for Drupal 7 use the Sub-pathauto (Sub-path URL Aliases) module, which is maintained from the same user who maintains the Pathauto module.

0
On

Try to use the node ID (Content: Nid) instead. See this blog post here http://dannyenglander.com/blog/using-views-contextual-filters-create-related-content-block-drupal-7