Hi, decided to post my first official plugin here. It’s a small helper function that we’ve used in a couple of projects and found that it cleaned up the code a bit and saved us a couple of minutes in each project.
“File Extension Icon” returns an icon or the file type as text for a specific file, based on the file’s extension.
Usage
The plugin returns an icon (or the type as text) for a specific file based on the file extension (ie. .gif, .jpg, .pdf). The default parameters works great with the Silk icons by FamFamFam but you can customize the icons any way you want.
Basic usage:
{exp:file_ext_icon width="10" height="10"}http://www.somesite.com/some_file.jpg{/exp:file_ext_icon}
Returns:
<img src="/images/icons/jpg.png" alt="jpg" width="10" height="10" />
Making use of the print_type parameter (to add CSS class in this case):
<li class="{exp:file_ext_icon print_type='yes'}/some_file.jpg{/exp:file_ext_icon}">Text</li>
Returns:
<li class="jpg">Text</li>
Parameters (examples):
- widht: the icon image width in pixels (default is 16). (10)
- height: the icon image height in pixels (default is empty) (10)
- path: the path to the icon folder with trailing slash (default is ‘/images/icons/’). (path/to/file/)
- ext: the extension of the icon files (default is ‘png’). (type)
- class: the class of the image (default is empty). (className)
- print_type: returns the extension of the file, ignoring all other parameters. (yes/no)
Download plugin:
