0

How do I override the template file of a view so that it no longer displays links in my view, but only the plain text?

This is a body field where the titles of the refenced entities are displayed as links. I would like to disable this for this view. I would like to do this via the template file for the view.

3
  • You generally wouldn't, as creating a link would be something managed in the view settings.
    – Jaypan
    Jun 27 at 22:27
  • Thanks, but unfortunately I can not change it via the View. I use "unformated list" to display the content. The function you probably mean is only available in views when I use fields.
    – Bavramor
    Jul 4 at 12:21
  • In that case, you're rendering entities, and you wouldn't alter a view template at all, you would instead edit the setting for the entity, which could possibly require editing a template, but again, usually done through the UI.
    – Jaypan
    Jul 4 at 23:14

1 Answer 1

0

As a workaround, you can use the striptags filter of twig to strip the anchor tags. https://twig.symfony.com/doc/3.x/filters/striptags.html

For example: {{ some_html|striptags('<a>') }}

2
  • Thank you for your idea. But I use the view template "views-view-unformatted.html.twig" . And when I try something like this {{row.content|striptags('<a>')}} I get the following error: The website encountered an unexpected error. Please try again later. TypeError: strip_tags(): Argument #1 ($string) must be of type string, array given in strip_tags() (line 1120 of /home/bavramor/data/Webdesign/Webseiten/landwehrcie-backup-drupal9-160522/vendor/twig/twig/src/Extension/CoreExtension.php).
    – Bavramor
    Jul 4 at 12:52
  • You need to pass string as a parameter. I guess row.content returns array. Jul 4 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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