In hook_preprocess_menu I am creating an array to send to the menu twig tpl (eventually it will be entity paragraph data but for now they are hard values as examples). However, I just receive array key invalid errors. How should this be formatted correctly for the template?
function hook_preprocess_menu__main_menu(&$vars) {
$node = \Drupal::routeMatch()->getParameter('node');
if($node->field_menu_highlights){
$highlight_values = $node->get('field_menu_highlights')->getValue();
foreach ($highlight_values as $key => $item){
$ent = \Drupal\paragraphs\Entity\Paragraph::load($item['target_id']);
$vars['highlight'][$key]['title'] = 'Title here';
$vars['highlight'][$key]['desc'] = 'Description here';
}
}
}
The template:
{% for value in highlight %}
{{ value }}
{% endfor %}
Error eg:
User error: "title" is an invalid render array key in Drupal\Core\Render\Element::children() (line 97 of core/lib/Drupal/Core/Render/Element.php).