I have a media file field field_file where the data is saved like:

title: Media Entity 01
file: media_entity_01.pdf

Using twig, is it possible to output the title of the file and the path?

When rendering the full entity using the 'Render Entity' display mode, I can only get the display to output something like this:

<a href="/media_entity_01.pdf">media_entity_01.pdf</a>
using twig like this:
{{ content.field_file }}

when i want it to output like this:

<a href="/media_entity_01.pdf">Media Entity 01</a>
using something like this:
<a href="{{content.field_file.entity.uri.value}}">{{content.field_file.GET_THE_TITLE}}</a>

Is this possible?


1 Answer 1


Got it figured out. Steps:

In Structure > Media Types > File > Manage Display, set the format as Generic File, click the gear icon, and turn on Use description as link text.

Next, inside of Structure > Media Types > File > Manage Fields, edit the field_media_file field and make sure the checkbox for Enable description field is checked. Now, when creating a media file entity, there is a description field that can be filled and will display as the link text.

  • 1
    As usual... this is buried in the CMS... albeit, in a logical location...
    – neuquen
    Apr 12, 2019 at 19:28

Your Answer

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

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