Forum:Way for template to run-through all extensions

I'm wondering if it's possible to make a template run-through all file extensions (i.e.,  , etc.) automatically, to conjure up the image.

For example, if this is the template:



how do I make is so that, just by inputting the file's name (parameter ), the template matches it with its correct extension to bring it up? How do I format the second parameter?

I'm also wondering how to format the template so that, if no file by that name exists, it does not display a dead link (such as ). Thanks. A .o. N 21:21, March 14, 2011 (UTC)


 * You'd want it to check with an (?) parser for each file extension. So, if it finds the file under .png, display that; else if it finds it under .jpg, display that; else .gif, etc. Once you've run through all of them, the last else should be what you want it to display if it doesn't find the picture.


 * OK, thanks, I'll try that. A .o. N  22:07, March 14, 2011 (UTC)


 * OK, I got the template down sort of. Here's what it looks like so far:

I just need the template own its own to change interchangeably between the different types of file extensions there are. That means replacing the  with something, I don't know. Or maybe there's another way? A .o. N 00:23, March 15, 2011 (UTC)


 * Like Monchoman said; the template would need to check all file extensions and once it finds a match it will display the image. Your code just needs to be extended to support more file extensions:




 * I don't know of a way for the template to do that on it's own. I don't think that's possible; what if you had Example.png and Example.jpg on the wiki - which image would the template choose then? Sovq 07:36, March 15, 2011 (UTC)


 * Well, hopefully, that'll never happen, or I'll just require that no two files can have the exact name. Anyway, I see what I was doing wrong: I was giving each one its own alternative, instead of having them grouped together. Thanks. A .o. N  14:24, March 15, 2011 (UTC)