I have created a new menu item and a callback function.

  $items['user/%user/enquiries'] = array(
    'title' => t('Enquiries'),
    'page callback' => '_client_enquiries',
    'access callback' => 'user_access',
    'access arguments' => array('view enquiries'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 1
 function _client_enquiries() {
   return t('Enquiries');

I am now going to CURL some json from a published google spreadsheet, and cherrypick, and then print some of it out in a table. My question.. what is the drupal way to do this? I think it would be to create a custom theme function which makes my processed json data available to a template, which I can somehow load onto my menu callback and output. If that is the case, could anyone give me some pointers/examples or a point in the right direction.


Much simpler:

function _client_enquiries() {

  $var_to_output = caculate_value_to_return();

  • Answered for simplicity, for more info see the above answer that may be a duplicate of this one. – sanzante May 21 '14 at 16:46
  • I'm not actually outputting any json. I will take some json from a feed, convert it with drupal_json_decode, extract the data I require and then theme that data into a table. I like your simple approach, but I want to keep the presentation layer separate from the business logic, which is why I thought the theme/template approach would be better? – davewilly May 22 '14 at 7:19
  • 1
    Ops, so I totally misunderstood your question. Then your aproach is right: use a custom theme function and call it in your hook menu callback. You don't have to load anything, it must be available. You can return the rendered HTML or a renderable array. – sanzante May 22 '14 at 8:06
  • No worries, my question isn't very clear! As per usual.. Thanks – davewilly May 22 '14 at 8:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.