Hello I want to display content of a view in Colorbox,

This looks similar to form; since

  $items['colorbox/form'] = array(
    'title' => 'Form',
    'page callback' => 'colorbox_form_page',
    'page arguments' => array(2),
    'access callback' => '_colorbox_form_page_access',
    'access arguments' => array(2),
    'type' => MENU_CALLBACK,
    'file' => 'colorbox.pages.inc',
  );

and

function colorbox_form_page($form_id) {
  $GLOBALS['devel_shutdown'] = FALSE; // Prevent devel module from spewing.

  switch ($form_id) {
    case 'contact_mail_page':
      module_load_include('inc', 'contact', 'contact.pages');
      print contact_site_page();
      break;
    case 'user_pass':
      module_load_include('inc', 'user', 'user.pages');
    default:
      $form = drupal_get_form($form_id);
      if (!empty($form)) {
        print $form;
      }
  }

  exit;
}

can be used to print a drupal form, I want to display a view using;

    $items['colorbox/view'] = array(
    'title' => 'View',
    'page callback' => 'colorbox_view_page',
    'page arguments' => array(2),
	'access callback' => '_colorbox_view_page_access',
	'access arguments' => array(2),
    'type' => MENU_CALLBACK,
    'file' => 'colorbox.pages.inc',
  );

and

function colorbox_view_page($view_id) {
    $view = views_get_view($view_id);
	print $view->execute_display('default', $args);
}

(since this requires views module to be installed, it could be added as a submodule or whatever it is called)

I tried the sample code above but it didn't work. What I got was the "Request unsuccessful: Forbidden" error, so I think this is an access issue.

Comments

tinker’s picture

The "Request unsuccessful: Forbidden" message normally indicates that access was denied loading the URL used in the colorbox. Start by opening the URLs used in a normal window, rather than colorbox, and see if you get an access denied page. In your case http://yourserver/colorbox/view and http://yourserver/colorbox/form

If you get access denied it probably due to the access callback function '_colorbox_view_page_access' and '_colorbox_form_page_access'. You did not include '_colorbox_view_page_access' which is not a function provided by the colorbox module. Have you defined it? For more info look for hook_menu documentation. You could try the following which shows the page to all users who can view content:

 $items['colorbox/view'] = array(
    'title' => 'View',
    'page callback' => 'colorbox_view_page',
    'page arguments' => array(2),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
    'file' => 'colorbox.pages.inc',
lsolesen’s picture

Category: feature » support
Status: Active » Fixed

There is an answer so marking as fixed.

Status: Fixed » Closed (fixed)
Issue tags: -views

Automatically closed -- issue fixed for 2 weeks with no activity.