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:


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:


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.

  • Hi, thanks for your detailed answer. The thing is, 'Accommodation" was not a content type, it's an entity.The main reason is I didn't need URLs for each of these hotels. So at that point I had 1) entity with term fields, so each hotel is tagged with their location 2) taxonomy for destinations. What I subsequently decided to do is create a content type called "Accommodation". Create nodes with the URLS I needed: "united-states/chicago/accommodation" Then have the entities (hotels) reference the nodes. Then I created a view that uses reference nodes and gets the ID from content URL. Nov 27 '18 at 1:55
  • Ah sorry missed that somehow. Creating a CT is one way of solving it if most of the CT features make sense in your case. But you can also expose the entity to Views: Expose custom entity to views, D7 Docs Views integration. You can find more tutorials online.
    – prkos
    Nov 27 '18 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.