Override load template function
Switch path from /epub201 to /epub3 when possible.

@param string $path
@param array $vars (optional)

@return string
@throws \Exception
971246
protected function loadTemplate( $path, array $vars = [] ) {

		$search = '/templates/epub201/';
		$replace = '/templates/epub3/';

		$pos = strpos( $path, $search );
		if ( false !== $pos ) {
			$new_path = substr_replace( $path, $replace, $pos, strlen( $search ) );
			if ( file_exists( $new_path ) ) {
				$path = $new_path;
			}
		}

		return parent::loadTemplate( $path, $vars );
	}
744899
public function match(string $path, array &$vars, string &$next_path) : bool
    {
        // parse query string: /path?foo=?bar&baz=qux
        $pos = strpos($path,'?');
        if ($pos !== false){
            $query = substr($path, $pos + 1);
            $path = substr($path, 0, $pos);
            parse_str($query, $auery_vars);
            $vars = array_replace($vars, $auery_vars);
        }
        // get first path section
        $pos = strpos(substr($path,1), '/');
        $first = $pos > 0 ? substr($path, 0, $pos + 1) : substr($path, 0);
        $next_path = $pos > 0 ? substr($path, $pos + 1) : '';
        // parse pattern
        $pattern = "@^/({$this->regex})$@";
        if (!preg_match($pattern, $first, $match) ){
            return false;
        }
        $varname = $this->varname;
        if (!empty($varname)){
            static $type_converters = [
                'string' => 'strval',
                'integer' => 'intval',
                'int' => 'intval',
                'float' => 'floatval',
                'double' => 'floatval',
                'boolean' => 'boolval',
                'bool' => 'boolval',
            ];
            $type_converter = $type_converters[$this->type] ?? null;
            $value = $type_converter ? ($type_converter)($match[1]) : $match[1];
            
            if (strpos($varname,'[]',strlen($varname)-3) !== false){
                $varname = substr($this->varname,0,-2);
                $vars[$varname][] = $value;
                $length = strlen($match[1]) + 1;
                $next = substr($path, $length);
                $pos = strpos(substr($next,1), '/');
                $next = substr($next, 0, $pos + 1);
                while(strlen($next)> 0 && preg_match($pattern, $next, $match))
                {
                    $value = $type_converter ? ($type_converter)($match[1]) : $match[1];
                    $vars[$varname][] = $value;
                    $length += strlen($match[1]) + 1;
                    $next = substr($path, $length);
                    $pos = strpos(substr($next,1), '/');
                    $next = $pos > 0 ? substr($next, 0, $pos + 1) : substr($next, 0);
                }
                $next_path = $next;
            }
            else{
                $vars[$this->varname] = $value;
            }
        }
        return true;
    }
900631
private static function getConfigurationFromInitializedTSFE($path)
    {
        /** @var $tmpl ExtendedTemplateService */
        $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
        $configuration = $tmpl->ext_getSetup($GLOBALS['TSFE']->tmpl->setup, $path);
        $configurationToUse = $configuration[0];
        return $configurationToUse;
    }
23093
public function compile(array $vars = [])
    {
        // start compilation
        if($this->compiling) {
            throw new \LogicException('Template is already compiling.');
        }
        $this->compiling = true;

        // extract user vars
        extract($vars);
        unset($vars);

        // start stream capture
        ob_start();

        // display file
        require $this->file;

        // stop stream capture
        $content = ob_get_clean();
        $content .= "\n\n";

        // compile layout
        if($this->layout) {
            list($layout, $vars) = $this->layout;
            $blocks = array_merge($this->blocks, ['__CONTENT__' => $content]);
            $content = $this->templater->render($layout, $vars, $blocks);
        }

        // end
        $this->compiling = false;
        return $content;
    }
90654
public function post($path, $vars = array()) {
    $request = $this->request();
    $request = $this->prepareRequest($request);

    $response = $request->post($this->endpoint . $path, $vars);
    return $this->handleResponse($response);
  }
1298065
protected function templateVars($file, $vars)
    {
        $start = $this->delimiter[0];
        $end = $this->delimiter[1];

        foreach ($vars as $var) {
            $replace = $start . $var . $end;
            if (in_array($var, $this->vars)) {
                File::put($file, str_replace($replace, $this->$var, File::get($file)));
            }
        }
    }
1257283
protected function loadFiles(
        string $path,
        array $excludes
    ) {
        $fileFinder = new FileFinder();

        /**
         * Building the real directory or file to work in.
         */
        $filesystem = new Filesystem();
        if (!$filesystem->isAbsolutePath($path)) {
            $path = getcwd() . DIRECTORY_SEPARATOR . ltrim($path, '/');
        }

        if (!is_file($path) && !is_dir($path)) {
            throw new Exception('Directory or file "' . $path . '" does not exist');
        }

        return $fileFinder
            ->findPHPFilesByPath(
                $path,
                $excludes
            );
    }
1193711
private static function template($t, $vars = array())
    {
        $t = preg_replace_callback('/\s+|<[^>]++>/', array('self', 'templateCb'), $t);
        array_unshift($vars, $t);
        $code = call_user_func_array('sprintf', $vars);
        return $code;
    }
1286967
public function load($path)
    {
        if (!file_exists($path)) {
            throw new PropelException(sprintf('File "%s" does not exist or is unreadable', $path));
        }
        ob_start();
        include($path);
        $contents = ob_get_clean();

        return $contents;
    }
1026194
private function twigLoad(string $path): ?\Twig_TemplateWrapper
    {
        try {
            return $this->twigEnv->load($path);
        } catch (TwigError $exc) {
            if (defined('WP_DEBUG') && WP_DEBUG) {
                throw $exc;
            }
        }
    }
558428
protected function _templatePath($path, array $vars = array())
    {
        if (strpos($path, '{') !== false) {
            preg_match_all('#\{\$([_a-z0-9]*)\}#i', $path, $matches);
            if (!empty($matches[1])) {
                foreach ($matches[1] as $var) {
                    $path = str_replace('{$' . $var . '}', isset($vars[$var]) ? $vars[$var] : null, $path);
                }
            }
        }
        return $path;
    }
1085174
public function load($path)
    {
        $path = $this->findAbsolutePath($path);
        $hash = Yaml::parse(file_get_contents($path));

        $features = $this->loader->load($hash);
        $filename = $this->findRelativePath($path);

        return array_map(function (FeatureNode $feature) use ($filename) {
            return new FeatureNode(
                $feature->getTitle(),
                $feature->getDescription(),
                $feature->getTags(),
                $feature->getBackground(),
                $feature->getScenarios(),
                $feature->getKeyword(),
                $feature->getLanguage(),
                $filename,
                $feature->getLine()
            );
        }, $features);
    }
763917
public function renderTwig($file, array $vars = array())
    {
        $page = Page::html();
        if (is_array($file)) {
            $vars = (isset($file['vars']) && is_array($file['vars'])) ? $file['vars'] : array();
            $default = (isset($file['default']) && is_dir($file['default'])) ? rtrim($file['default'], '/').'/' : null;
            $file = (isset($file['file']) && is_string($file['file'])) ? $file['file'] : '';
            if ($default && $template = $this->getFiles($file, $default)) {
                $file = array_pop($template);
            }
        }
        $base = $page->dir['page'];
        $cut = strlen($base);
        if (strpos($file, $this->blog->folder.'themes/') === 0) {
            $dir = $this->blog->folder.'themes/';
            $file = substr($file, strlen($dir));
            $theme = strstr($file, '/', true).'/';
            $dir .= $theme;
            $file = substr($file, strlen($theme));
            $loader = $this->getTwig()->getLoader();
            $loader->addPath($dir, 'theme');
            $dir = substr($dir, $cut);
        } elseif (strpos($file, $base) === 0) {
            $dir = substr(dirname($file).'/', $cut);
            $file = basename($file);
        } else {
            throw new \LogicException("The '{$file}' is not in your website's Page::dir folder.");
        }
        if (!is_file($base.$dir.$file)) {
            throw new \LogicException("The '{$dir}{$file}' file does not exist.");
        }
        if (is_null($this->asset)) { // our first time here
            $this->getTwig()->setParser(new Parser($this->getTwig()));
        }
        $this->asset = array(
            'dir' => $dir,
            'chars' => $page->url['chars'],
        );
        $save = array(
            'template' => $dir.$file,
            'vars' => $vars,
            'start' => microtime(true),
        );
        try {
            $html = $this->getTwig()->render($dir.$file, array_merge($vars, $this->vars));
            $save['output'] = $html;
        } catch (\Exception $e) {
            $html = '<p>'.$e->getMessage().'</p>';
            $save['error'] = $e->getMessage();
        }
        $save['end'] = microtime(true);
        $save['time'] = $save['end'] - $save['start'];
        self::$templates[] = $save;

        return $html;
    }
169416
public function build(string $path, array $vars = []): string
    {
        $this->path = $path;
        $this->vars = $vars;

        unset($path, $vars);

        ob_start();

        extract($this->vars);

        try {
            /** @noinspection PhpIncludeInspection */
            include $this->path;
        } catch (Exception $e) {
            ob_get_clean();
            throw $e;
        }

        $this->path = $this->vars = null;

        return ob_get_clean();
    }
348712
public function renderTemplate($template, $vars)
    {
        $twig = $this->getContainer()->get('twig');

        $template = $twig->createTemplate($template);

        return $template->render($vars);
    }
599333
protected function formatTemplate($template, array $vars)
    {
        $output = $template;
        $token = $this->buildToken();

        foreach ($vars as $key => $value) {
            $replacement = sprintf($token, $key);

            if (!$this->isFlagEnabled(self::ALLOW_NEWLINES)) {
                $value = $this->sanitizeNewlines($value);
            }

            if (false !== strpos($output, $replacement)) {
                $output = str_replace($replacement, $value, $output);
            }
        }

        $output = $this->removeExtraTokens($token, $output);

        return $output;
    }
736624
private function loadFile(string $path)
    {
        if (!file_exists($path)) {
            throw new Exception('Configuration file "' . $path . '" is not found');
        }

        if (!is_readable($path)) {
            throw new Exception('Configuration file "' . $path . '" is not readable');
        }

        // Include file
        $content = include $path;

        if (!\is_array($content)) {
            throw new Exception("Passed file \"$path\" is not array");
        }

        return $content;
    }