3

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?

3
  • suppose there exists multiple occurrences of same name in different folders. Then how do you want to manage this situation? Commented Oct 8, 2014 at 12:36
  • It should just be the normal fallback.
    – Alex
    Commented Oct 8, 2014 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
    Commented Oct 8, 2014 at 12:43

1 Answer 1

1

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 and acknowledge you have read our privacy policy.

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