0

I am looking to display my own block on user profile page. The block will to display the username of the user whom profile we are viewing.

I went ahead and created a view, show users, block.

Added contextual filter for UIID, Raw value from URL. Path component 2

User profile and a user sub-pages have this structure: domain.com/u/username (user main profile page) domain.com/user/845/posts (user posts, where 845 is uid)

How can I add a contextual filter that will work on both cases? The username is changed a little by path auto. Dashes, commas, uppercases and such are removed so that may be why raw value from URL is not working.

Btw, I am open to creating a custom user profile by creating user/% view for user profile.

  • Rather than using views by its own, I suggest you to use EVA module or Panels module, this two module let you consider how to pass argument to your block, exp you can use an available field of node as argument – Alireza Tabatabaeian Sep 25 '18 at 20:52
  • The thing is that the block is shown on the user profile page. How can I pass author information to the view? Because the block is not shown on the node. – Progonat Sep 26 '18 at 1:21
1

The alias doesn't matter, you get the argument for a contextual filter from the internal path, no matter if the URL in the browser was aliased (unless you enable the option "Use path alias"). For a user profile the internal path is /user/[uid].

For the user ID there is also a contextual filter "User ID from route context", this filter is able to get the user without specifying in which path position it is.

  • It worked. I was using UUID instead of User ID contextual filter. That's why it was not working. But your explanation really helped though. – Progonat Sep 26 '18 at 13:48

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.