{% macro mimeIcon(type) %} {# mapping forkawesome and mime type https://gist.github.com/colemanw/9c9a12aae16a4bfe2678de86b661d922 #} {% set mapmime = { 'image': 'fa-file-image-o', 'audio': 'fa-file-audio-o', 'video': 'fa-file-video-o', 'application/pdf': 'fa-file-pdf-o', 'application/msword': 'fa-file-word-o', 'application/vnd.ms-word': 'fa-file-word-o', 'application/vnd.oasis.opendocument.text': 'fa-file-word-o', 'application/vnd.openxmlformats-officedocument.wordprocessingml': 'fa-file-word-o', 'application/vnd.ms-excel': 'fa-file-excel-o', 'application/vnd.openxmlformats-officedocument.spreadsheetml': 'fa-file-excel-o', 'application/vnd.oasis.opendocument.spreadsheet': 'fa-file-excel-o', 'application/vnd.ms-powerpoint': 'fa-file-powerpoint-o', 'application/vnd.openxmlformats-officedocument.presentationml': 'fa-file-powerpoint-o', 'application/vnd.oasis.opendocument.presentation': 'fa-file-powerpoint-o', 'text/plain': 'fa-file-text-o', 'text/html': 'fa-file-code-o', 'application/json': 'fa-file-code-o', 'application/gzip': 'fa-file-archive-o', 'application/zip': 'fa-file-archive-o', } %} {% set icon = 'fa-file-o' %} {% for key,val in mapmime %} {% if type starts with key %} {% set icon = val %} {% endif %} {% endfor %} {# TODO improve mapping mime type and friendly name https://gist.github.com/rosskmurphy/3724501 #} {% set maptype = { 'fa-file-word-o': 'office document/texte', 'fa-file-excel-o': 'office document/tableur', 'fa-file-powerpoint-o': 'office document/presentation', } %} {% set label = type %} {% for key, val in maptype %} {% if icon == key %} {% set label = val %} {% endif %} {% endfor %} {{ label|capitalize }} {% endmacro %}