I want to check if a file exists in any skin and thus the result of $block->getSkinUrl('foo.png') points to a valid URL.

How can I accomplish that?

  • suppose there exists multiple occurrences of same name in different folders. Then how do you want to manage this situation? – Rajeev K Tomy Oct 8 '14 at 12:36
  • It should just be the normal fallback. – Alex Oct 8 '14 at 12:40
  • Here is a wild idea. Somehow get all the themes you have in your fallback mechanism (I don't know how, that's why is a wild idea) then do a glob('skin/fronend/*/*/foo.png') and see if any of the results match one of the themes. – Marius Oct 8 '14 at 12:43

This seems to work

 * Get skin URL of image in language specific version - fall back to English (en)
 * @param $ressource string - %s for language
public function getSkinUrlFallback($resource)
    $file = sprintf($resource, $this->getLang());
    $skinBase = Mage::getBaseUrl('skin', Mage::app()->getStore()->isCurrentlySecure());
    $skinUrl = $this->getSkinUrl($file);
    $path = str_replace($skinBase, '', $skinUrl);
    if (file_exists(Mage::getBaseDir('skin') . DS . $path)) {
        return $skinUrl;
    } else {
        $file = sprintf($resource, 'en');
        return $this->getSkinUrl($file);

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.