4

I have created a question node type using CCK and would like to show all of the questions which users create on a tab on their profile page.

The way I have done this feels a little indirect. I have:

  1. Created a view which lists all of a user's questions and made a block to display it.
  2. Configured the block so that it only displays on the right path ("user/*/questions").
  3. Created an entry in hook_menu for this path. Used a page callback which calls a function which creates an empty page (see below).

Is there a more direct way to do this by, e.g., attaching the view directly to the profile page?

The code in hook_menu() is:

$items['user/%/questions'] = array(
  'title'            => 'Your Questions',
  'description'      => 'User Questions',
  'page callback' => 'answers_blank_page',
  'access arguments'  => array('create question content'),
  'type'     => MENU_LOCAL_TASK,
  'weight' => 9,
);

The page callback is simply:

function answers_blank_page () {
  return '';
}

3 Answers 3

4

There isn't any need to use a custom module for this: The Views module already allows you to associate a URL to a view and make the view appears as a menu tab.

The following screenshots are for Views 7.x-3.x-dev, but the settings are present also in previous versions of the module.
Under "Page settings," there are two options: "Path" and "Menu." The screenshots shows the settings used for a view implemented by a third-party module (the Flag module), whose view is shown as menu tab.

path settings

menu settings

1
  • Just wanted to say "thanks" ... while it took a little while for me to get back to this, this solution worked great. (It turns out I even ended up wanting to create a sub-menu and the same set of ideas here worked for using Views built-in capabilities to make that). Much simpler than what I had.
    – chipcleary
    Commented Jun 7, 2011 at 3:08
3

Create a new page view, and then configure it to provide a menu item, specifically a tab, at path user/%/questions.

1

It should work just by creating a page display, setting the path appropriately; no need to do the tricky steps you used.

Edit: you must also specify a menu item for the display.

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.