for a given template file string, is it possible to check that it exists before the block is rendered and if not choose a different template to render.

my block therefore has a template set to customer/account/test.phtml

In the beforeToHtml i want to make sure that this can be found using the full fallback mechanism. i.e. that if it cannot be found in the current theme package that it can be found in base. If both of these fail then i will set a different template.

I can not find any examples in core code that do anything similar.

  • 1
    Can you explain a little your problem? What you are asking here does not look like a good practice. When you create an module you should make sure the templates involved in it exist.
    – Marius
    Jun 10, 2013 at 19:58
  • 1
    I agree with Marius, it should be: checking using some logic, if conditional1 setTemplate(a) else setTemplate(b). For example: <checkout_cart_index> -> <action method="chooseTemplate"/>
    – ivantedja
    Jun 11, 2013 at 2:37

1 Answer 1


Checking if a file exists and otherwise using a fallback shouldn't be done as a general approach for performance reasons, but I can imagine cases where that would make sense.

In general you can use

$templateFile = Mage::getBaseDir('design') . DS . $block->getTemplateFile();
if (! file_exists($templateFile)) {

This checks if the current template exists anywhere in the configured fallback or the base theme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.