سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top