I have a loop populating multiple render arrays, and my output is not appearing as expected.
$count = 0;
foreach ($result as $row) {
//do stuff
if ($is_a_link_list) {
//do more stuff
$id = 'link_list_a' . $count;
$content[$id] = array(
//render array - link list
);
} else {
$id = 'promo_list_a' . $count;
$content[$id] = array(
//render array - title
);
$id = 'promo_list_b' . $count;
$content[$id] = array(
//render array - body
);
}
$count++;
}
So in a given result set I'd expect:
---promo list title promo list body ---link list =item1 =item2 =item3 (more results)
What I'm getting:
---promo list title promo list body ---link list =item1 =item2 =item3 promo list body ---promo list title ---promo list title ---link list =item1 =item2 =item3 promo list body ---link list =item1 =item2 =item3
So does the key of the render array matter? (Other than needing to be unique)
Looking at the markup output it's apparent that I need to render my render arrays as list items; I think this means a nested render array?
HTML source:
$content[$id]
to$content[$count]['element_name']
I then used this answer to wrap each of my render array chunks in a container element; prefacing the if/else block with$content[$count] = array( '#type' => 'container', '#attributes' => array( 'class' => array('class-name'), ), );