What is the best way of include ctools_include('ajax'); into a page already defined by another module?
I'm trying to use ctools ajax framework to replace content (similar to how the ctools example hello world works).
I've tried to integrate the ctools hello world example into my existing code but it looks like none of the setup is run. When clicking on the the link it forwards to the menu link defined rather than changing the content.
EDIT:
I've used ctools_include('ajax') on the following hooks (all hooks confirmed correct by added debug to them):
- nodeapi (alter)
- preprocess node
This is my hook_nodeapi('alter') code, which inserts the text as per the example module.
ctools_include('ajax'); $links =array(); $links[] = ctools_ajax_text_button(t('Hello world!'), "defs/nojs/test", t('Replace text with "hello world"')); $node->body .= theme('item_list', $links, t('Actions')); $node->body .= theme('ctools_ajax_sample_container', '<h1>' . t('Sample Content') . '</h1>'); This is my menu item.
$items['defs/%ctools_js/test'] = array( 'page callback' => 'br_defintions_funkyajax', 'access arguments' => array('access content'), 'page arguments' => array(1), 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); This is my callback function from the menu item.
function br_defintions_funkyajax($js = NULL) { $output = '<h1>' . t('Hello World') . '</h1>'; if ($js) { ctools_include('ajax'); $commands = array(); $commands[] = ctools_ajax_command_html('#ctools-sample', $output); ctools_ajax_render($commands); // this function exits. } else { return $output; } }