Add a view with a contextual filter not on a node/taxonomy page Druapl 7 - I have a taxonomy vocabulary called ‘Destinations’ and an entity created called “accommodation”. The accommodation entity contains names of individual accommodations, to simplify, let’s use hotels. So:

Entity type: accommodation


Hotel X - San Diego
Hotel Y - Barcelona
Hotel Z - Rome


What I want to do is create pages that show which accommodation is available in which city. So I need to create a page for each:

/san-diego/accommodation
/barcelona/accommodation
/rome/accommodation

I can do this by adding a custom page:

/admin/structure/pages/add

I have created a view but can’t quite get my head around how to use contextual filters and relationship to show only the hotels available at each accommodation page.

How will Drupal “know” that this page should show hotels in San Diego:

/san-diego/accommodation

I understand contextual filters and relationships and use them all the time, but can’t figure out how to do this in the case. 

What is the best way to create these pages and add the view?
You already have Views that list all the content tagged with a Taxonomy term. The Views is called Taxonomy term, but it is a Content type Views listing nodes that have been tagged with a particular term. 

You can Clone the Taxonomy term view and edit the clone to adjust it to your specific needs for Accomodation. Keep the original Taxonomy term View disabled if you don't need it. But you can keep it enabled along with the cloned instance too. 

You want to change the Path to accommodation/%, the first part shouldn't be variable. 

Also add a new Filter Content: Type and choose Accommodation only.

You can also change to use Fields instead of Content for more control over what is shown in each Accommodation result.  

With this setting you will get pages that take term ID as the argument. If your San Diego term has ID 12, then if you visit the page /accommodation/12 you will see Accommodation nodes tagged with San Diego. 

You don't have to create those pages in any other place than Views, they're already working when you type the correct path with term ID into your browser location bar. 

If you want to list all the available terms you can use the Summary in the When the filter value is NOT in the URL option of the Contextual filter. This way when users visit the /accommodation path they see a list of locations. When they click on a location they see accommodation nodes associated with it. 

You can use the Menu option to add the page to a menu of your choice. 

Use term names instead of IDs

To get the term name to appear in the path instead of the TID you have to add the Relationship to the term, and use a Contextual filter Term name that uses that Relationship. (Remove old Contextual Has term ID.)

I've covered details in another Question: How to setup view to filter based on second URL parameter?

Be careful about the Case settings, use dashes ;) 

With this configuration your path will be /accommodation/san-diego.