Skip to content

Instantly share code, notes, and snippets.

@dergachev
Created February 1, 2012 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dergachev/1719744 to your computer and use it in GitHub Desktop.
Save dergachev/1719744 to your computer and use it in GitHub Desktop.
<?php
// menu callback that returns NULL, used for web services
function article_callback_json($node) {
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
print json_encode($arr); // {"a":1,"b":2,"c":3,"d":4,"e":5}
return NULL;
}
//menu callback that returns a string for Drupal to wrap in the page layout
function article_callback_string($node) {
return "<h2>" . $node->title . "</h2> <div>" . $node->body . "</div>";
}
//menu callback that returns a renderable array for Drupal to render
function article_callback_array($node) {
return array(
'#theme' => 'node_article',
'#article_title' => $node->title,
'#article_body' => $node->body,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment