I am loading node content to a specific div with Ajax. Is it possible to load a fully themed and rendered node (themed via page--node--1.tpl.php) with Ajax?
I have a custom module controlling my Ajax functions. From what I understand, the code below should be returning a fully themed node - but it is not doing so:
function ajax_reader_init() {
drupal_add_js('misc/jquery.form.js');
drupal_add_library('system','drupal.ajax');
}
/**
* Implements hook_menu()
*/
function ajax_reader_menu() {
$items['ajax-reader'] = array (
'page callback' => 'ajax_link_response',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
return $items;
}
function ajax_link_response($type = 'ajax', $nid = 0) {
$output = _ajax_reader_load_noder($nid);
if ($type == 'ajax'){
$commands = array();
$commands[] = ajax_command_replace('.main', '<div class="main">'.$output.'</div>');
$page = array(
'#type' => 'ajax',
'#commands' => $commands
);
ajax_deliver($page);
} else {
$output = '<div class="main">'.$output.'</div>';
return $output;
}
}
function _ajax_reader_load_noder($nid = 0) {
$node = node_load($nid);
if($node) {
$vnode = node_view($nid);
return theme("node", $vnode);
}
}