Create a modal popup I want to show a modal popup in drupal 7. On searching the web I came to know that it can be done using the ctools module itself. Here is the code I tried:

function codeexpertz_menu() {
  $items['codeexpertz/%ctools_js/page'] = array(
    'title' =&gt; 'Demo CTools Page',
    'access callback' =&gt; TRUE,
    'page callback' =&gt; 'codeexpertz_ctools_page_example',
    'page arguments' =&gt; array(1),
    'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}

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;
}


The link i referred is here

I added &lt;a href="codeexpertz/nojs/page" class="ctools-use-modal"&gt;Modal Window&lt;/a&gt; to my page.tpl.php file directly for now to test it. However when I click on the link I get redirected on the destination page rather than showing the content in a modal.

I tried this is a fresh installation also, but all in vain.
You should use the ctools_modal_text_button function to render your "popup-opener" links.

ctools_include('ajax');
ctools_include('modal');
ctools_modal_add_js();
$link = ctools_modal_text_button('Open popup', 'codeexpertz/nojs/page', 'alt here', 'no-class');


You can have a look what the Modal Entities modue does in the modal_entities_generate_link() function for additional style settings.