New answers tagged

1

Menu Delete module is now available for modern Drupal (Drupal 8 and Drupal 9)!


0

I needed to add some classes to my link. field_url is a link field. I didn't have content in the Twig context. {{ node.field_url[0] }} gives me a \Drupal\Core\Url object. {% set link = node.field_url[0] | view %} This is a filter from the Twig Tweak module. It returns a render array. I can now output my link like this: <a href="{{ link['#url'] | ...


0

Actually there is much simpler solution using https://www.drupal.org/project/twig_field_value module <a href="{{ content.FIELD_LINK_NAME|field_value|first['#url']|render }}"> {{ content.FIELD_LINK_NAME|field_value|first['#title'] }} </a> This will work for both internal and external links.


0

For Drupal 8 or 9, if you want to add some markup around the text, you can do like this: // If you know the route name. $url = Url::fromRoute('route_name'); // If you just know the path. $url = Url::fromUserInput('/yourpath'); // Create a link with HTML tag around the text. $button = Link::fromTextAndUrl(Markup::create('<span>My page</span>'), $...


0

For the homepage enter: <front>#your-anchor in the link field


Top 50 recent answers are included