I am trying to display the data from a REST API (URL: 'http://api.kivaws.org/v1/loans/38239/lenders.json') to display in a block. Below is my code. It is not working, any hint on why will be sincerely appreciated.
/**
* Implements hook_block_info().
*/
function restapiexample_block_info() {
// This example comes from node.module.
$blocks['kiva'] = array(
'info' => t('Kiva Test Block'),
'cache' => DRUPAL_NO_CACHE
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function restapiexample_block_view($delta = '') {
// This example is adapted from node.module.
$block = array();
switch ($delta) {
case 'kiva':
$block['subject'] = t('Kiva Example');
$block['content'] = array(
'#theme' => 'page',
'#markup' => kiva_list_loans(),
break;
}
return $block;
}
function kiva_list_loans() {
$request = drupal_http_request('http://api.kivaws.org/v1/loans/38239/lenders.json');
return drupal_json_decode($request->data);
}
You can try the URL, good JSON data is being returned. Error I receive is several instances of the following text in the $messages area: "Warning: Cannot use a scalar value as an array in drupal_render() (line 5859 of /home/drupalpro/websites/example7.dev/includes/common.inc)"
UPDATE 1: With help from comments/answer below, I made some progress. from my function "kiva_list_loans()", I am able to see the response in my $page array. I changed the '#theme' in my "$block['content']" in hook_block_view to 'page' - but still I only see the word "Array". How to get this to render?