Drupal 7: CTools modal popup simple page with example

The CTools module helps us to implement popup functionality in Drupal. Using CTools modal popup we can create Custom pages, forms, blocks into popups. The below example will demonstrate creating simple Modal popup page with sample code.

Sample Code:

/**
 * Implements hook_menu().
 */
function codeexpertz_menu() {
  $items['admin/test/sample/%ctools_js/page'] = array(
    'title' => 'Demo CTools Page',
    'access arguments' => TRUE,
    'page callback' => 'codeexpertz_ctools_page_example',
    'page arguments' => array(3),
    'type' => MENU_CALLBACK,
  );
}
 
/**
 * Callback function for Popup page.
 */
function codeexpertz_ctools_page_example($js) {
  $output = "Sample CTools popup functionality for Demo purpose.";
  if ($js) {
    // Required includes for ctools to work:
    ctools_include('modal');
    ctools_include('ajax');
    return ctools_modal_render("Demo", $output) ;
  }
  return $output;
}
 
#Popup Click Link
print l(t('Modal Window'), 'admin/test/sample/nojs/page', array('attributes' => array('class' => 'ctools-use-modal')));
Category: