0

I want to display ctools modal. I tried the following code.

/**
 * Implements hook_menu().
 */
function my_module_menu() {
  $items['my_module/%ctools_js/test-page'] = array(
    'title' => 'Demo CTools Page',
    'page callback' => 'my_module_modal',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function my_module_modal($js) {
  $output = '<div class="content">' . t('Test content?') . '</div>';
  dsm($js);
  if ($js) {
  ctools_include('ajax');
    ctools_include('modal');

  ctools_modal_add_js();
    return ctools_modal_render('Define as start matrix', $output);
  }

  return $output;
}

The link where I click is

<a href="/my_module/nojs/test-page" class="ctools-use-modal">Open modal</a>

But it returns me only the content of the page with no modal. When I printed the $js variable, it is displaying 0. While the javascript is enabled in the browser. I have checked it with multiple browsers .

What can be the issue?

0

I have found the solution.

You need to add these 3 lines of code to the page where the link <a href="/my_module/nojs/test-page" class="ctools-use-modal">Open modal</a> is displaying.

ctools_include('ajax');
ctools_include('modal');
ctools_modal_add_js();

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.