0

I currently have a view that shows on the user profile page (as a block). I got it to show results of the content for the current logged in user.

This works great for normal users as they will only be able to see their current profile page. However, I want it to show the content for the shown profile, not the current user, since admins that view other user profiles will not see that user's content.

Is there a way to set the view to get the uid of the profile page rather than the logged in user?

These are the view settings I have right now are:

CONTEXTUAL FILTERS
   Content: Author uid
      Provide default value: User ID from logged in user
RELATIONSHIPS
   Content: Author

1 Answer 1

2

You need to adjust where the contextual filter is retrieving the UID from.

When you provide a value for your contextual filter, you want to retrieve the raw UID value that's coming from Drupal's path system. To do this, look at the When the Filter Value is not available section.

Selecting Raw value from URL will use Drupal's internal path for the currently viewed page (e.g. /node/XXX, /user/YYY, etc.). The path component refers to which one of the "subdirectories" in the path to reference (e.g. 1 = "user", 2 = YYY, in the previous example).

In your example, you want a Path Component of 2 (i.e. the UID from /user/XXX profile page).

enter image description here

3
  • could you explain what the "Path component" is and why is should be 2 and how 2 = profile page? It works but I don't understand why? I'm thankful for the fix but I also want to understand it as well. Why 2? Commented Oct 14, 2015 at 20:56
  • O is it saying the 2nd value in the url path and being that it is /user/some number the 2 would be that number? Commented Oct 14, 2015 at 21:03
  • I elaborated on what Type & Path component refer to in my answer. Hopefully, that clears up how contextual filtering works URL paths.
    – Shawn Conn
    Commented Oct 14, 2015 at 21:11

Your Answer

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

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