0

I have a site with custom home pages depending on role. The homepages are assigned with hook_menu (hook_menu associates a URL with a function that returns a $html string.)

For one particular role, I need to generate a homepage that incorporates a view. I am looking at a list of views hooks, and not sure were to start.

In summary, how do I display a view that is generated from one of my hook_menu functions?

Edit: I am currently looking into this code example from http://lucor.github.com/2011/10/drupal7-how-display-block-programmatically/ The view is in now in a block.
I have not yet figured out what I either one of the parameters are suposed to be set to.

$block = block_load($module, $delta); print render(_block_gAet_renderable_array( _block_render_blocks( array($block) )));

3

You have many ways to apply what you are looking for.

The easy way is to use Context module with Empty Front Page module

Another way is to write your own module, something like the following code:

function myfront_menu() {
  $items = array();

  $items['frontpage'] = array(
    'title' => 'My homepage',
    'page callback' => 'myfront_front_page',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function myfront_front_page() {
  global $user;

  if (in_array('administrator', array_values($user->roles))) {
    return views_embed_view('view_name', 'display_id');
  }

  if (in_array('authenticated user', array_values($user->roles))) {
    return views_embed_view('view_name', 'display_id');  
  }

  if (in_array('role2', array_values($user->roles))) {
    return views_embed_view('view_name', 'display_id');  
  }

  if (in_array('role3', array_values($user->roles))) {
    return views_embed_view('view_name', 'display_id');  
  }

  return '';
}
1

You could propably use

views_embed_view()    

http://api.drupal.org/api/views/views.module/function/views_embed_view/7

0

You can try using context module (http://drupal.org/project/context) on your case or even use this for a better implementation of displaying different types of homepage depending on the user role without the hassle of using custom code.

You can preview what it can do here http://www.drupalove.com/drupal-video/context-module.

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.