0

I have an urls:

  • website.com/portfolio-entries/23
  • website.com/portfolio-entries/25

I would like to make an view for them to display node which has id the same as last part of url (from last / to the end).

I have red the description for View > Url (administration panel > Content > Views > My_view):

This view will be displayed by visiting this path on your site. You may use "%" in your URL to represent values that will be used for contextual filters: For example, "node/%/feed". If needed you can even specify named route parameters like taxonomy/term/%taxonomy_term

So I set it to portfolio-entries/%entry_id (I hope I understood it right).

But how now make this view display only sinlge entry which has the id set to %entry_id?

I've tried with View > Filters (add) > ID but I can only set there hard-coded values (e.g. 23 makes this view display only entry #23). How can I place there my %entry_id?

In other words I was reproducing steps from https://www.ostraining.com/blog/drupal/views-specific-node/ (it's for Drupal 7 but it works the same way in Drupal 8) but instead of har-coding the id value I want to take it from last part of the url.

1 Answer 1

0

Normally the parameter is not named, it is a single % without name:

portfolio-entries/%

The example node/%/feed is also a single % in the middle part of the url. The third part of the url is a fixed feed, so that only urls with a /feed at the end will match.

To use this parameter for filtering you need to set a contextual filter in the advanced settings. If you only have one parameter, this filter will automatically get this, when selecting the field you want to filter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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