0

I have created a view that has many fields including a link field. I am using a twig template. my view twig name is views-view-fields--dashboard--block_3.html.twig It works nicely but I need to render a path in an anchor tag. here is my code.

<a href="{{ fields.view_node.content}}">
    <div class="mail-contnet">
        <h5>{{ fields.title.content }}</h5>
        <span class="mail-desc">{{ fields.body.content }}</span>
        <span class="time">{{ fields.created.content }}</span>
    </div>
</a>

In the anchor tag, I am getting the link but it has twig debugging wrappers. The result is bellow

<a href="    
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'views_view_field' -->
<!-- BEGIN OUTPUT from 'core/modules/views/templates/views-view-field.html.twig' -->
/vanss/ques-curabitur-arcu-erat-accumsan-id-imperdiet-et-0
<!-- END OUTPUT from 'core/modules/views/templates/views-view-field.html.twig' -->    
">

and I need only the path. I have already tried the twig_field_value module. but when I {{ fields.view_node.content|field_value}}

Error: Cannot use object of type Drupal\Core\Render\Markup as array in Drupal\twig_field_value\Twig\Extension\FieldValueExtension->isFieldRenderArray() (line 171 of modules\contrib\twig_field_value\src\Twig\Extension\FieldValueExtension.php).

Now I am looking for how to render the value of an anchor tag without any wrapper.

4
  • I think you have enabled Twig Debugging in services.yml file ,just make debug = false
    – Vikram8888
    Nov 6, 2019 at 7:37
  • Better put the Twig code in the rewrite section of the field in UI, see drupal.stackexchange.com/questions/218022/…
    – 4uk4
    Nov 6, 2019 at 9:13
  • @4k4 I have to use some inline CSS and some conditions which I can't get through rewrite fields Nov 6, 2019 at 9:35
  • But for that part you have shown in the question you can rewrite the field. For other things you can still use the views templates or other methods like a custom field handler.
    – 4uk4
    Nov 6, 2019 at 9:47

1 Answer 1

1

If you want to remove twig debug comments you can use striptags filter

Like the following:

{{ fields.view_node.content|striptags}}
2
  • Working Like a Charm. Thanks Nov 6, 2019 at 11:31
  • Welcome I'm glad that help
    – berramou
    Nov 6, 2019 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.