tags:

views:

161

answers:

2

I'm currently wrestling with a views relationship-argument puzzle.

I have a Flag setup called Favorites, so that users can favorite site content. I also am using Content Profiles and Pathauto. Now I'm adding a views content attachment to the user content profile to display the user's chosen favorites.

Pathauto's default content profile path is: member/[title-raw] - so that a typical alias for a user's profile page is: member/john-smith (please bear in mind that the profile node id isn't the same as the user id)

And here's my views setup: Relationship: flags:favorites - BY: Any user

Argument: This is where my understanding breaks down. I need to somehow get the username or uid out of the URL of the current profile.

Any ideas of the correct argument to get this thing to work? I've been trying out all the possibilities that occur to me, and so far no luck.

Thanks

A: 

if you're willing to use custom php code in order to fetch the argument, http://api.drupal.org/api/function/drupal%5Fget%5Fnormal%5Fpath/6 is your friend. you can pass it the alias you're visitting with arg(0).'/'.arg(1)

barraponto
Thanks for the reply. I do know about the arg() function, but can't make it work in this instance. If you know a specific way to make it work in my scenario, please specify.
Michael D
sorry. my code is returning you the nid of the content profile. you need its user uid. try loading the node through node_load then return the user from the node object. i hope you find your way out...
barraponto
+1  A: 
  1. In your View setup, click on + in Arguments to add an argument.
  2. In your argument setup, select "User" from the "Groups" drop down.
  3. Check "User: Name"
  4. Click "Add" button
  5. Save your view

As long as this is your only argument, you just have to pass in user name in the URL. In your example, so see the view for john-smith, you would navigate to http://example.com/viewname/john-smith.

That would be for page type view.

If you are creating a block view type, you cannot pass arguments in the URL. For a block type view, follow these steps:

  1. In your View setup, click on + in Arguments to add an argument.
  2. Select "PHP Code" for "Default argument type"
  3. Enter the following for the PHP code,

    if (arg(0) == 'viewname' && arg(1) != '') { return arg(1); }

Now that block will get arguments from the URL, similar to what occurs for a page view.

Mike Munroe
Thank you for the detailed explanation Mike! Unfortunately, not working. I need to start experimentation on this thing from a simpler base and build complexity on a working prototype. So I'll start with the core user profile with no url alias and go from there.
Michael D
Michael D, you may want to try to create a page type view that lists favorites for a user. Then, try to turn that into a block that works following the info I provided. At that point, you can configure that block to only show on the user profile page.
Mike Munroe

related questions