Score:0

How can I print the link to the media file?

th flag

I have an image media type. I would like to display the image and the link to the file in the rendered Media. I don't want the image to be a link to the file.

I couldn't find a link to the file field in Manage display. I looked at the media.html.twig file, but I could not understand how to link to the file.

How can I add the media file link in Manage display?

{#
/**
 * @file
 * Default theme implementation to present a media item.
 *
 * Available variables:
 * - media: The media item, with limited access to object properties and
 *   methods. Only method names starting with "get", "has", or "is" and
 *   a few common methods such as "id", "label", and "bundle" are available.
 *   For example:
 *   - entity.getEntityTypeId() will return the entity type ID.
 *   - entity.hasField('field_example') returns TRUE if the entity includes
 *     field_example. (This does not indicate the presence of a value in this
 *     field.)
 *   Calling other methods, such as entity.delete(), will result in
 *   an exception.
 *   See \Drupal\Core\Entity\EntityInterface for a full list of methods.
 * - name: Name of the media item.
 * - content: Media content.
 * - title_prefix: Additional output populated by modules, intended to be
 *   displayed in front of the main title tag that appears in the template.
 * - title_suffix: Additional output populated by modules, intended to be
 *   displayed after the main title tag that appears in the template.
 * - view_mode: View mode; for example, "teaser" or "full".
 * - attributes: HTML attributes for the containing element.
 * - title_attributes: Same as attributes, except applied to the main title
 *   tag that appears in the template.
 *
 * @see template_preprocess_media()
 *
 * @ingroup themeable
 */
#}
<div{{ attributes }}>
  {{ title_suffix.contextual_links }}
  {{ content }}
</div>
leymannx avatar
ne flag
`{{ file_url(media.field_media_image.entity.fileuri) }}` maybe?
leymannx avatar
ne flag
With Twig Tweak maybe even `{{ media_file_url(media) }}` or `{{ media|file_url }}` works. https://www.drupal.org/project/twig_tweak/issues/2924925 or https://www.drupal.org/project/media_entity_image/issues/2856093
leymannx avatar
ne flag
Found all that in 10 seconds on Google.
Rico avatar
th flag
thank you, it works
leymannx avatar
ne flag
Which one? Add it as answer.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.