I remember in Drupal 7, this was possible. I need to add some HTML before a field and I don’t want to edit it in the Twig file. Is it somehow possible to add prefixes / suffixes by using the template_preprocess_field
function?
I already tried something like that, but with no success:
function MYTHEME_preprocess_field(&$variables, $hook) { $element = $variables['element']; if ($element['#field_name'] === 'field_genre') { $element[0]['#prefix'] = '<div class="project-info">'; } if ($element['#field_name'] === 'field_duration') { $element[0]['#suffix'] = '</div>'; } }