Display file size next to file link I'm trying to override the file-link.html.twig to display the size next to the file link (also the file MIME type, but I think I can figure that out once I figure out how to display the size) but so far I've been failing spectacularly. I assume this must be super simple and I'm missing something obvious.

Using kint($variables) in the function themename_preprocess_file_link(&amp;$variables) I see the filesize:

$args array (1)
array (15
'file' =&gt; Drupal\file\Entity\File(27) 
"contents" tab:
    protected values -&gt; array(13)
    'filesize' =&gt; array(1)
    'x-default' =&gt; string(7) "2245389"


But I can't figure out how to turn this into a variable I can use in a template file. 

I tried following How can I override template_preprocess_file_link function? but then I couldn't figure out what was suppose to be the variable to use in the template file. Also, his "code" just seems to be same as what is on https://api.drupal.org/api/drupal/core%21modules%21file%21file.module/function/template_preprocess_file_link/8.6.x.
Using HOOK_preprocess_field(&amp;$variables):

/**
 * Implements HOOK_preprocess_field().
 *
 * @inheritdoc
 */
function HOOK_preprocess_field(&amp;$variables) {
  $element = $variables['element'];
  // Check that field_name is set.
  if (isset($element['#field_name'])) {
    // Checking for field_name, but could check for field_type.
    if ($element['#field_name'] == 'field_name') {
      // Set our file size to a variable.
      $fileSize = $element[0]['#file']-&gt;filesize-&gt;value;
      // Edit our title for the field display.
      $element[0]['#file']-&gt;filename-&gt;value = $element[0]['#file']-&gt;filename-&gt;value . ' ' . $fileSize;
    }
  }
}




Using HOOK_preprocess_file_link(&amp;$variables):

/**
 * Add the "file-link.html.twig" template to your theme and adjust as needed.
 * 
 * Twig variables:
 * - {{ fileLinkDisplay.fileBundle }}
 * - {{ fileLinkDisplay.fileCreatedTime }}
 * - {{ fileLinkDisplay.fileChangedTime }}
 * - {{ fileLinkDisplay.fileFid }}
 * - {{ fileLinkDisplay.fileLangcode }}
 * - {{ fileLinkDisplay.fileMime }}
 * - {{ fileLinkDisplay.fileName }}
 * - {{ fileLinkDisplay.fileOwnerId }}
 * - {{ fileLinkDisplay.fileOwnerName }}
 * - {{ fileLinkDisplay.fileOwnerUserPictureUrl }}
 * - {{ fileLinkDisplay.fileSize }}
 * - {{ fileLinkDisplay.fileSizeFormatted }}
 * - {{ fileLinkDisplay.fileStatus }}
 * - {{ fileLinkDisplay.fileUrl }}
 * - {{ fileLinkDisplay.fileUuid }}
 */

function HOOK_preprocess_file_link(&amp;$variables) {
  if (isset($variables['file'])) {
    $variables['fileLinkDisplay'] = [
      'fileBundle' =&gt; $variables['file']
        -&gt;bundle(),
      'fileCreatedTime' =&gt; $variables['file']
        -&gt;getCreatedTime(),
      'fileChangedTime' =&gt; $variables['file']
        -&gt;getChangedTime(),
      'fileFid' =&gt; $variables['file']
        -&gt;fid-&gt;value,
      'fileLangcode' =&gt; $variables['file']
        -&gt;langcode-&gt;value,
      'fileMime' =&gt; $variables['file']
        -&gt;getMimeType(),
      'fileName' =&gt; $variables['file']
        -&gt;getFilename(),
      'fileOwnerId' =&gt; $variables['file']
        -&gt;getOwnerId(),
      'fileOwnerName' =&gt; $variables['file']
        -&gt;getOwner()-&gt;name-&gt;value,
      'fileOwnerUserPictureUrl' =&gt; file_create_url($variables['file']
        -&gt;getOwner()-&gt;user_picture-&gt;entity-&gt;uri-&gt;value),
      'fileSize' =&gt; $variables['file']
        -&gt;getSize(),
      'fileSizeFormatted' =&gt; format_size($variables['file']
        -&gt;getSize()),
      'fileStatus' =&gt; $variables['file']
        -&gt;status-&gt;value,
      'fileUrl' =&gt; file_create_url($variables['file']
        -&gt;getFileUri()),
      'fileUuid' =&gt; $variables['file']
        -&gt;uuid-&gt;value,
    ];
  }
}


See https://gitlab.com/prestosaurus/file-link-display/blob/master/file_link_display.module

Then your file-link.html.twig might look like:

{#
/**
 * @file
 * Theme override for a link to a file.
 *
 * @see template_preprocess_file_link()
 */
#}
{{ attach_library('classy/file') }}
&lt;span{{ attributes }}&gt;{{ icon }} {{ link }} {{ fileLinkDisplay.fileSize }} {{ fileLinkDisplay.fileMime }}&lt;/span&gt;