src/TwigComponent.php
public function render($template, $data = [], $return = true)
    {
        if ($template instanceof Page) {
            $page = $template;
            $file = $page->templateFile();
            $data = $this->data($page, $data);
        } else {
            $file = $template;
            $data = $this->data(null, $data);
        }

        // check for an existing template
        if (!file_exists($file)) {
            throw new Exception('The template could not be found');
        }

        // merge and register the template data globally
        $startData = Tpl::$data;
        Tpl::$data = array_merge(Tpl::$data, $data);

        // load the template
        if (pathinfo($file, PATHINFO_EXTENSION) === 'twig') {
            $twig = TwigEnv::instance();
            $result = $twig->renderPath($file, Tpl::$data, $return, true);
        } else {
            $result = Tpl::load($file, [], $return);
        }

        // reset the template data
        Tpl::$data = $startData;

        return $result;
    }
public function render($template, $data = [], $return = true)
    {
        if ($template instanceof Page) {
            $page = $template;
            $file = $page->templateFile();
            $data = $this->data($page, $data);
        } else {
            $file = $template;
            $data = $this->data(null, $data);
        }

        // check for an existing template
        if (!file_exists($file)) {
            throw new Exception('The template could not be found');
        }

        // merge and register the template data globally
        $startData = Tpl::$data;
        Tpl::$data = array_merge(Tpl::$data, $data);

        // load the template
        if (pathinfo($file, PATHINFO_EXTENSION) === 'twig') {
            $twig = TwigEnv::instance();
            $result = $twig->renderPath($file, Tpl::$data, $return, true);
        } else {
            $result = Tpl::load($file, [], $return);
        }

        // reset the template data
        Tpl::$data = $startData;

        return $result;
    }
Renders the template by page with the additional data
@param Page|string $template
@param array $data
@param boolean $return
@return string
@throws Exception