Extract Url & Title from link field in Drupal 8?

后端 未结 11 665
一生所求
一生所求 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条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 05:51

    If you want to do this in a field template instead of a node template do this:

    {% for item in items %}
      {{ item.content['#url'] }}
      {{ item.content['#title'] }}
    {% endfor %}
    

    Alternately, if this is not a multi-value field you can just do this instead:

    {{ items|first.content['#url'] }}
    {{ items|first.content['#title'] }}
    

提交回复
热议问题