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()->config->get('defaultTemplateExtensions') as $extension)
{
if (IOHelper::fileExists($template . "." . $extension))
{
...
}
}