Compile the template using the given data.

@param $template
@param $data
@return mixed
176836
protected function compile($template, $data)
    {
        foreach($data as $key => $value)
        {
            $template = preg_replace("/\\$$key\\$/i", $value, $template);
        }
        return $template;
    }
738857
public function partial($template, $data = array()) {
		return parent::render($template, array_merge($this->layoutData, (array)$data));
	}
1124135
public function loadTemplate($template, $data = array(), $process = true)
    {
        $path = $this->findTemplate($template);

        if (! $path) {
            unset($this->_paths[$template.'.php']);
            throw new LibBaseTemplateException($template.' template not found for '.$this->getIdentifier());
            return false;
        }

        return $this->loadFile($path, $data, $process);
    }
667356
protected function render($template, $data = [])
    {
        $view = new View();
        $view->type(View::VIEW_TYPE_CELL);
        $view->set($data);
        $className = get_class($this);
        $namePrefix = '\View\Cell\\';
        $name = substr($className, strpos($className, $namePrefix) + strlen($namePrefix));
        $view->context(str_replace('\\', DIRECTORY_SEPARATOR, $name));
        return $view->render($template);
    }
821662
public function renderTemplate($templatePath = null, $data = [])
    {
        $renderedTemplate = $this->view->renderTemplate($templatePath, $data);
        return $renderedTemplate;
    }
765291
public function render($template, array $data = array())
    {
        $data = array_merge($data, $this->website->helpers());

        $data['config'] = $this->website;

        $renderer = $this->website->renderer();

        return $renderer->render($template, $data);
    }
149627
public function fetch($template, $data = []) {
        if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
            // 获取模板文件名
            $template = $this->parseTemplate($template);
        }
        // 模板不存在 抛出异常
        if (!is_file($template)) {
            throw new \Exception('template not exists:' . $template, $template);
        }
        $this->template = $template;

        extract($data, EXTR_OVERWRITE);
        include $this->template;
    }
284283
public static function render($template = '', $data = [])
    {
        $templatesPath = realpath(__DIR__ . '/../templates');
        $loader        = new \Twig_Loader_Filesystem($templatesPath);
        /** @var object $twig */
        $twig         = new \Twig_Environment($loader);
        $templateFile = $template . '.html';

        return $twig->render($templateFile, $data);
    }
1014548
public function fetchBlock($template, $block, $data = [])
    {
        $data = array_merge($this->defaultVariables, $data);

        return $this->environment->loadTemplate($template)->renderBlock($block, $data);
    }
749360
public function render(string $template = "", array $data = []): string
    {
        try {
            if ($template) {
                $filename = dirname(__DIR__, 4)
                          . DIRECTORY_SEPARATOR
                          .  "layout"
                          . DIRECTORY_SEPARATOR
                          . str_replace("..", "", $template);
                if (!is_file($filename)) {
                    throw new Exception ($filename . " is not a file");
                }
                $this->__construct();
                extract($data);
                ob_start();
                include $filename;
                $this->obContents = ob_get_contents();
                ob_end_clean();
            }
            return $this->obContents ? $this->obContents : parent::render();
        } catch (Throwable $e) {
            throw new ViewException(
                "Can't render " . static::class . " " . $e->getMessage()
            );
        }
    }
75200
public function fetch($template, $data = array())
    {
        $view = $this->render($template, $data);

        return ($view) ? $view->render() : '';
    }
216710
public function compile($template)
    {
        $name = md5($template);
        
        if (isset(self::$callbacks[$name])) {
            return self::$callbacks[$name];
        }
        
        $file = $this->cache . '/' . $this->prefix . $name . '.php';

        if (is_dir($this->cache) && file_exists($file)) {
            $callback = include($file);
        } else {
            $code = Compiler::i($this, $template)->compile();
            
            if (is_dir($this->cache)) {
                file_put_contents($file, $code);
            }
            
            //called like: function($data) {};
            $callback = @eval('?>'.$code);
            //$this->checkEval($code);
        }
        
        self::$callbacks[$name] = $callback;
        
        return $callback;
    }
163730
public function mail($template, $data = array(), &$css = array())
    {
        $this->twig->addFunction(new \Twig_SimpleFunction('css', function ($file) use (&$css) {
            $css[] = $file;
        }));
        $template = $this->twig->loadTemplate($template);
        return $template->render($data);
    }
640517
public static function vsprintf($template, array $data, \Closure $onError = null)
    {
        if (!is_string($template)) {
            return '';
        }
        if ($template && !(empty($data))) {
            try {
                $template = vsprintf($template, $data);
            } catch (\Exception $e) {
                if ($onError) {
                    call_user_func($onError, $e);
                }
            }
        }

        return $template;
    }
1254193
public function editor($template, $data = null, array $params = [])
    {
        $resource = 'templates/'.$template.'/editor';
        $params = array_merge([
            'key' => $this->key,
            'workspace' => $this->workspace,
            'signature' => $this->createSignature($resource)
        ], $params);

        if ($data)
        {
            $params['data'] = self::dataToString($data);
        }

        return $this->baseUrl.$resource.'?'.http_build_query($params);
    }
802713
public function render($template, array $data = [])
    {
        ob_start();
        $this->requireTemplate($template, $data);

        while ($extend = array_pop($this->inherits)) {
            ob_clean();
            $this->requireTemplate($extend, $data);
        }

        return ob_get_clean();
    }
1233288
public function render(string $template, array $data = []): string
    {
        // we store the current state of the template variables
        // so that we have isolated cases on multiple calls to render()
        $backupVariables = $this->thisShouldMakeItUniqueCodeCollabTemplateHtmlVariables;

        if (!empty($data)) {
            $this->thisShouldMakeItUniqueCodeCollabTemplateHtmlVariables = $data;
        }

        try {
            ob_start();

            /** @noinspection PhpIncludeInspection */
            require $template;
        } finally {
            $output = ob_get_clean();
        }

        $this->thisShouldMakeItUniqueCodeCollabTemplateHtmlVariables = $backupVariables;

        return $output;
    }