0

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' => 'Demo CTools Page',
    'access callback' => TRUE,
    'page callback' => 'codeexpertz_ctools_page_example',
    'page arguments' => array(1),
    'type' => 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 <a href="codeexpertz/nojs/page" class="ctools-use-modal">Modal Window</a> 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.

1 Answer 1

1

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.

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.