public static function findTemplate (\Twig_Loader_Filesystem $filesystem, $name)
    {
        $name = self::normalizeName($name);
        self::validateName($name);
        list($namespace, $shortname) = self::parseName($name);
        $paths = $filesystem->getPaths($namespace);
        if (empty($paths)) {
            throw new Twig_Error_Loader(sprintf('There are no registered paths for namespace "%s".', $namespace));
        }
        foreach ($paths as $path) {
            if (is_file($path . '/' . $shortname)) {
                if (false !== $realpath = realpath($path . '/' . $shortname)) {
                    return $realpath;
                }
                return $path . '/' . $shortname;
            }
        }
        throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $paths)));
    }