You are here

file-entity-download-link.html.twig in File Entity (fieldable files) 8.2

Default theme implementation to display the file entity as a download link.

Available variables:

  • file: The full file object.
  • download_link: The download link.
  • icon: a string identifying the type of the file, which can be used for example to show an icon (see the comment below on how to do that).
  • file_size: The formatted file size.
  • attributes: An array of HTML attributes, intended to be added to the main container of this template.

File

templates/file-entity-download-link.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation to display the file entity as a download link.
  5. *
  6. * Available variables:
  7. * - file: The full file object.
  8. * - download_link: The download link.
  9. * - icon: a string identifying the type of the file, which can be used for
  10. * example to show an icon (see the comment below on how to do that).
  11. * - file_size: The formatted file size.
  12. * - attributes: An array of HTML attributes, intended to be added to the main
  13. * container of this template.
  14. *
  15. * @ingroup themeable
  16. */
  17. #}
  18. {#
  19. In order to have the file icons from the classy theme, you can just extend this
  20. template and add:
  21. {{ attach_library('classy/file') }}
  22. to the beginning of your file.
  23. #}
  24. {%
  25. set classes = [
  26. 'file',
  27. 'file--mime-' ~ file.getMimeType()|clean_class,
  28. 'file--' ~ icon|clean_class
  29. ]
  30. %}
  31. <span {{ attributes.addClass(classes) }}>
  32. {{ download_link }}
  33. <span class="file-size">({{ file_size }})</span>
  34. </span>