Skip to content

Instantly share code, notes, and snippets.

@ao5357
Created June 12, 2012 23:16
Show Gist options
  • Save ao5357/2920757 to your computer and use it in GitHub Desktop.
Save ao5357/2920757 to your computer and use it in GitHub Desktop.
Nodes as json, etc. in D6
name = JSON Nodes
description = Lets you print nodes as json for ctools, or some other formats
dependencies[] = ctools
package = Chaos tool suite
core = 6.x
/**
* Implements hook_menu()
*/
function jsonodes_menu(){
$items['plain/%/node/%node'] = array(
'title' => 'Node',
'page arguments' => array(1,3),
'access arguments' => array('access content'),
'page callback' => 'jsonodes_node_plain_callback',
'type' => MENU_CALLBACK
);
return $items;
}
/**
* Menu callback to display nodes plain (mostly for modals)
*/
function jsonodes_node_plain_callback($nojs = NULL, $node) {
if(!node_access('view', $node)){
drupal_access_denied();
return;
}
$themed_node = node_view($node);
switch ($nojs) {
case 'ajax':
ctools_include('modal');
print ctools_modal_render($node->title, $themed_node);
break;
case 'nojs':
drupal_goto(drupal_lookup_path('alias', 'node/' . $node->nid));
break;
default:
drupal_set_title($node->title);
print $themed_node;
}
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment