0

Magento frontend theme fallback to backend

Hi - we use a frontend pdf program that uses backend/adminhtml templates - and now these are not found. I think what we would like and have to to is tell Magento to:

  • first look for the theme in frontend
  • and if not found then look in the backend theme templates

question: Can this be easily achieved?

I understand you can influence frontend fallback - but don't know how you can add the functionality to look for all missing template files in the backend template model if frontend fails to find it

thanks in advance

  • Is moving the templates into the frontend not an option? – Smartie Sep 8 '15 at 13:14
  • no ... too dangerous whenupdating – snh_nl Sep 8 '15 at 13:16
3

It's not something you might be able to do with settings but if it's for a specific module you can change it's code a little to use the adminhtml theme.

To set the template that should be used at runtime you can use the following

 $package =  Mage::getDesign()->getPackage();
 $template = Mage::getDesign()->getTheme('template');

 Mage::getDesign()->setArea('adminhtml')
    ->setPackageName('default') 
    ->setTheme('default');

[...]
// your code goes here
[...]

 Mage::getDesign()->setArea('frontend')
    ->setPackageName($package) 
    ->setTheme($template);

This sets the templating engine to use the backend template. Now after you're done rendering the PDF restore it to the frontend shop values.

  • superb. And suppose one had to switch 'between' current and adminthml; how would we then store current? then set adminthml? the retrieve current? ---- just asking .... – snh_nl Sep 8 '15 at 13:16
  • Updated my answer\ – Sander Mangel Sep 8 '15 at 13:25
  • $package = Mage::getDesign()->getPackage(); seems to sometimes give some problems for example when run via cron "Call to undefined method Fooman_SpeedsterAdvanced_Model_Core_Design_Package::getPackage()" – ShirtsofHolland Mar 4 '16 at 6:48
  • Suppose we would make it: $currentDesignArea = Mage::getDesign()->getArea(); Mage::getDesign()->setArea('adminhtml'); [code here]; Mage::getDesign()->setArea($currentDesignArea); Maybe package and template do not have to be explicitely set because the fall back mechanism will alsways find default/default in adminthml ... when we are done we re-set the Area – ShirtsofHolland Mar 4 '16 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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