简体   繁体   中英

Get URL of a link field in Drupal 8 Views-View-Fields

I have a template views-view-fields.html.twig and created a view. I can access all the fields easily and also the link field. But it generates <a> . I want to extract link from this field.

I have searched SO and found some solution but they didn't work for me.

{{ fields.field_find_out_more_link[0]['#url'] }}

{{ fields.field_find_out_more_link.0['#url'] }}

{{ fields.field_find_out_more_link.url }}

Can anyone point me to right direction?

这对我来说在views-view-fields.html.twig为链接字段工作:

<a href="{{ fields.view_node.content|render|striptags|trim }}">text</a>

Well, maybe I am a bit late but I think I found a proper answer to this.

In your View, you need to have a Link to Content field. Then, in the configuration of the field, you need to set to true the option "Show url as text". Finally, in your twig, you can set your button like:

<a href={{ fields.view_node.content|striptags }} class="btn">Yeah</a>

Hope this helps.

Based on Sébastien Gicquel answare i used it like this in a views-view-fields.html.twig template with a custom link field:

  <a href="{{ fields.field_link.content|striptags|trim }}">
    {{ fields.field_image.content }}
    {{ fields.title.content }}
  </a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM