Drupal 8 /9 : use User Name instead of UID in view tab (url)

Profile picture for user a.berramou
Azz-eddine BERRAMOU 11 December, 2020

Let's say you want to create page view displaying special content for example (articles) created by specific user, and you want to use user name in the url instead of the UID, something like /articles-by/admin instead of /articles-by/1.

How to use User Name instead of UID in view tab ?

To do so follow the following steps:

  1.  Create a view page with the path /articles-by/%user
  2. Create a user relationshipview user relationship
  3. Add contextual filters with User Nameview user contextual filters
  4. Configure your contextual filter ((author) User: Name) like this by adding a Specify validation criteria:
    Specific validation creataria
  5. Save your view configuration.

Now you have a view list articles created by user with a user name in the url instead of uid as number, by going to https://example.com/articles-by/admin you will see the articles created by the admin and so on!
I hope this was helpful.

Share :