3

I've got an Magento admin console extension that enables a model window across the entire Magento admin console. In Magento 1.7, I can include the factory default CSS file with the following

$layout->getBlock('head')->addCss('lib/prototype/windows/themes/magento.css');    

However, in Magento 1.6, this file isn't in the skin folder, it's in the 'js_css' folder, and I need to use this

$layout->getBlock('head')->addItem('js_css', 'prototype/windows/themes/magento.css')

Is there an elegant, straight forward way for me to ensure this file is properly included across all versions of Magento without resorting to version sniffing and without resorting to making my own copy of the file.

dualed
  • 10,262
  • 1
  • 26
  • 29
Alana Storm
  • 164,128
  • 91
  • 395
  • 599

3 Answers3

3

I went this this for the time being — leaving the question open in the hopes something better comes along.

        //would fail if Magento lives in a sub-folder named base
        $skin_url = $design->getSkinUrl('lib/prototype/windows/themes/magento.css');
        $parts = explode('/',$skin_url);
        if(in_array('base', $parts))
        {
            $head->addItem('js_css', 'prototype/windows/themes/magento.css');
        }
        else
        {
            $head->addCss('lib/prototype/windows/themes/magento.css');    
        }
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
2

I don't know if this suggestion is any better but you could check where the file exist and let that determine which method to call.

beeplogic
  • 478
  • 3
  • 10
  • Yeah, maybe just store file_get_contents($file) in a variable and check if it's empty or not? – pspahn Aug 16 '12 at 20:06
2

Probably the safest way would be to distribute your own version of the file with your package.

  • You will have absolute certainty of where the file resides after package installation
  • No unnecessary FS hits
  • No dependency on the version provided by Magento (of course this can backfire, as always)
barbazul
  • 608
  • 6
  • 8
  • What happens when my file interferes with the magento file on a magento where Magento code uses it? – Alana Storm Aug 16 '12 at 20:22
  • Wow! You said "magento" three times in the same sentence. Time to take a break? Your question is exactly what I meant by backfiring. Is the same logic behind not overwriting core classes in local. I wouldn't use my own proposed solution in any circumstances, and I like your proposal better. But, if avoiding version sniffing (or version-dependent file structure checks) is a must, then I cannot see another solution – barbazul Aug 18 '12 at 23:00