I am developing a theme and trying to send custom vars to a twig menu template (since it pulls data from config) and have a loop to add variables in preprocess:
foreach($attributes as $attribute => $values){
$variables[$element . '_attributes']->SetAttribute(
$attribute,
$values
);
// Also tried:
$variables[$element]['#attributes'][$attribute][] = $values;
}
This function passes data to the template $variables as confirmed by kint, but SetAttribute returns a protected class property instead of the render array, while pushing to ['#attributes'] returns the attribute keys correctly but the arrays are empty...