What is the best way to test if a file exists without knowing which file extension a Craft install is using for templates? Craft allows users to use whatever template extension they prefer: .html or .twig or something custom.

We can check if a file exists like so: 

IOHelper::fileExists($filePath)


Is there any way to know which extension we want to be testing for?  By default Craft supports both html and twig in the supported extensions config setting.

Right now, I have the following which feels a bit clunky:

foreach (craft()-&gt;config-&gt;get('defaultTemplateExtensions') as $extension) 
{
    if (IOHelper::fileExists($template . "." . $extension)) 
    {
        ...
    }
}
That's exactly how I'd do it.

It doesn't make much sense, but there's nothing stopping a user from having both extensions for a template like:

/index.html
/index.twig


And your existing code would cover both cases.