I'm trying to figure out how to extend a common Link Field in Drupal 8 with an HTML entity (like ยป).
My first try was a preprocess function for the field. Unfortunately I didn't manage to set the html
option of the link to true
Here's how I tried it
function MYTHEME_preprocess_field(&$variables) {
if ($variables['element']['#field_name'] == 'field_slideshow_link'){
foreach ($variables['items'] as $idx => $item) {
$variables['items'][$idx]['content']['#title'] = $variables['items'][$idx]['content']['#title'] . " <span>»</span>";
$variables['items'][$idx]['content']['#url']->setOption('html', true);
}
}
}
This didn't work. So the only solution I came up with was to manually generate a Link within the template. With just doesn't feel right. Here's how I did it
<a href="{{ node.field_slideshow_link.0.url }}">{{ node.field_slideshow_link.0.title }} <span>»</span></a>
Has anyone an idea how to solve this problem more elegantly?