How to change the target of a file for a multiple file field in drupal 8? I have a content type with a file field: field_document.

It contains multiple files.

I chose Generic file as display format in manage display setting.

I need to change the target attribute of the files that drupal generates for me. How can I do that?

So instead of this

OUTPUT from 'core/themes/stable/templates/field/file-link.html.twig'

&lt;span class="file file--mime-application-pdf file--application-pdf"&gt;
  &lt;a
    href="http://somedomain.com/sites/default/files/document/2017/test_document_8.pdf"
    type="application/pdf; length=8108"
    title="test_document.pdf"&gt;Test Document&lt;/a&gt;
&lt;/span&gt;


I would need this: target="_blank"

&lt;span class="file file--mime-application-pdf file--application-pdf"&gt;
  &lt;a
    href="http://somedomain.com/sites/default/files/document/2017/test_document_8.pdf"
    type="application/pdf; length=8108"
    title="test_document.pdf"
    target="_blank"&gt;Test Document&lt;/a&gt;
&lt;/span&gt;
You can do this in a hook, but also in a custom file-link template in your theme. Check if the file link has a class specific to a pdf file and then set the target attribute:

file-link.html.twig

{% if attributes.hasclass('file--application-pdf') %}
  &lt;span{{ attributes.setAttribute('target', '_blank') }}&gt;{{ link }}&lt;/span&gt;
{% else %}
  &lt;span{{ attributes }}&gt;{{ link }}&lt;/span&gt;
{% endif %}