开发者

Views/Flags relationship-argument puzzle

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 brea开发者_运维百科ks 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


  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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜