I generally give Twig files a "twig" extension. As I understand it these Twig files are usually recognised as HTML like files by Linux using some sort of scan algorithm. So Nemo for example represents these files with a web icon and clicking on properties shows the file type as "Text (text/html)". However sometimes when there is no actual HTML near the top of the file Linux recognises the file as plain text instead. On such files I tried adding a HTML comment as the first line:

<!-- Twig file -->

Which works OK for Twig macro files, but not for regular templates as it causes an error:

Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'A 
template that extends another one cannot have a body in "std.twig" at line 
1.' in /var/www/html/vendor/twig/twig/lib/Twig/Parser.php:379 Stack trace:

I know that it is possible to put a "html" extension after the "twig" extension, so the full file name is for example:


But that is cumbersome.

So I was wondering if instead it is possible to give Linux (Mint in my case) a new file type, and perhaps have a different icon in Nemo from either the text or HTML icons?


1 Answer 1


Create a custom mime type e.g. text/x-twig (and - optionally - use a custom icon1 for that particular mime type) via a new source xml file:


with the following content:

<?xml version="1.0"?>
 <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  <mime-type type="text/x-twig">
    <comment>twig files</comment>
    <glob pattern="*.twig"/>
    <icon name="text-x-twig"/>

then update your mime database

update-mime-database ~/.local/share/mime

1:Keep in mind that the "icon name" must match the actual icon name(s) sans extension from your icon theme; default location for mime type icons is /path/to/your/icon/theme/${SIZE}/mimetypes (where sizes are e.g. 16x16, 24x24 etc so for each size you should have a corresponding icon unless you opt to use a svg icon for all sizes)

  • I don't have a XDG_DATA_HOME variable. I do have a XDG_DATA_DIRS variable which leads to two icon directories /usr/share/cinnamon/icons and /usr/share/icons whose contents are too numerous to list in this comment.
    – gornvix
    Apr 24, 2017 at 20:34
  • 1
    @tyebillion - just replace that with the actual path to your icon theme e.g. /usr/share/icons/Faenza/24x24/mimetypes; if you don't use a custom icon set i.e. if you use the default icon set from upsteam you'll have to create a custom icon theme (which inherits the theme from upstream) and add your icon. Apr 24, 2017 at 20:42
  • I guess that "gnome" is my theme, but there is also a "Mint-X" directory and others in /usr/share/icons.
    – gornvix
    Apr 24, 2017 at 20:46
  • 1
    @tyebillion - you don't know what icon theme you're using ? If you're on gnome run gsettings get org.gnome.desktop.interface icon-theme in a terminal. If you're on cinnamon I suspect it's the same only replace gnome with cinnamon not sure though... and other DEs, I don't know. Apr 24, 2017 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .