Extract Url & Title from link field in Drupal 8?

后端 未结 11 650
一生所求
一生所求 2021-01-31 05:29

I\'m trying to retrieve the URL and the Title values of a Link field in Drupal 8.

In my custom controller, I retrieve the nodes with:<

11条回答
  •  梦毁少年i
    2021-01-31 05:56

    You can render either the uri or text of a link field directly in the twig template. In the case of a node you can use either of the following within the twig template file (assumes the machine name of your link field is field_link):

    {{ node.field_link.uri }}
    
    {{ node.field_link.title }} 
    

提交回复
热议问题