Skip to content

Instantly share code, notes, and snippets.

@cafuego
Created April 10, 2013 00:05
Show Gist options
  • Save cafuego/5350570 to your computer and use it in GitHub Desktop.
Save cafuego/5350570 to your computer and use it in GitHub Desktop.
Custom module to provide static JSON map data
<?php
function mymod_menu() {
$items['view/path/that/returns/the/json] = array(
'title' => t('JSON Callback'),
'page callback' => 'mymod_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function mymod_callback() {
$json = "/some/file/on/disk.js";
die(file_get_contents($json));
}
@hotwebmatter
Copy link

Line 3 is missing a closing single quote character.

The gist should read:

<?php
function mymod_menu() {
  $items['view/path/that/returns/the/json'] = array(
    'title' => t('JSON Callback'),
    'page callback' => 'mymod_callback',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

function mymod_callback() {
  $json = "/some/file/on/disk.js";
  die(file_get_contents($json));
}

Note that this also fixes the syntax highlighting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment