1

How can I render arrays in div structure in drupal?. I am having a select list with ajax callback.Everytime I choose option, it's fields get fetched into an array. Now how can I show that array fields value?

$nodes = array();
    $output = array();
    $i=0;
    $nids = db_select('node', 'n')
      ->fields('n', array('nid'))
      ->condition('type', 'article', '=')
      ->execute()
      ->fetchCol();
    $nodes = node_load_multiple($nids);
     foreach ($nodes as $node => $value) {
      $output[$i]['title'] = $value->title;
      $output[$i]['body'] =$value->body['und']['0']['value'];
      $i++;
    }
    return output;

If I used return theme('item_list', array('items' => $output));, it is not working for me. Please help.

1 Answer 1

1

After a research of 20 minutes, I came to this answer.theme('item_list', array('items' => $output)); This function follows a simple array key value structure.It doesn't support multiple idexes. so remove $i from array, and it will work.

1
  • 1
    It is explained in the docs itself. items: An array of items to be displayed in the list. If an item is a string, then it is used as is. If an item is an array, then the "data" element of the array is used as the contents of the list item. If an item is an array with a "children" element, those children are displayed in a nested list. All other elements are treated as attributes of the list item element. api.drupal.org/api/drupal/includes%21theme.inc/function/…
    – niksmac
    Jul 14, 2015 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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