简体   繁体   English

获取Drupal 8 Views-View-Fields中的链接字段的URL

[英]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. 我有一个模板views-view-fields.html.twig并创建了一个视图。 I can access all the fields easily and also the link field. 我可以轻松访问所有字段以及链接字段。 But it generates <a> . 但是它生成<a> I want to extract link from this field. 我想从此字段中提取链接。

I have searched SO and found some solution but they didn't work for me. 我已经搜索了SO,找到了一些解决方案,但它们对我没有用。

{{ 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". 然后,在该字段的配置中,需要将“显示网址显示为文本”选项设置为true。 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: 基于SébastienGicquel answare,我在带有自定义链接字段的views-view-fields.html.twig模板中像这样使用了它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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