Compile template.

@param Template $template

@return mixed
970754
public function compile(Template $template)
    {
        // Otherwise, we look for a compile method
        $method = 'compile'.ucfirst($template->getName());
        if (!method_exists($this, $method)) {
            return null;
        }

        return $this->$method($template);
    }
1292475
public function compileTemplate(Smarty_Internal_Template $template, $nocache = false)
    {
        if (empty($template->properties['nocache_hash'])) {
            $template->properties['nocache_hash'] = $this->nocache_hash;
        } else {
            $this->nocache_hash = $template->properties['nocache_hash'];
        }
        // flag for nochache sections
        $this->nocache = $nocache;
        $this->tag_nocache = false;
        // save template object in compiler class
        $this->template = $template;
        // reset has nocache code flag
        $this->template->has_nocache_code = false;
        $save_source = $this->template->source;
        // template header code
        $template_header = '';
        if (!$this->suppressHeader) {
            $template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
            $template_header .= "         compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
        }

        if (empty($this->template->source->components)) {
            $this->sources = array($template->source);
        } else {
            // we have array of inheritance templates by extends: resource
            $this->sources = array_reverse($template->source->components);
        }
        $loop = 0;
        // the $this->sources array can get additional elements while compiling by the {extends} tag
        while ($this->template->source = array_shift($this->sources)) {
            $this->smarty->_current_file = $this->template->source->filepath;
            if ($this->smarty->debugging) {
                Smarty_Internal_Debug::start_compile($this->template);
            }
            $no_sources = count($this->sources);
            if ($loop || $no_sources) {
                $this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type);
            }
            $loop++;
            if ($no_sources) {
                $this->inheritance_child = true;
            } else {
                $this->inheritance_child = false;
            }
            do {
                $_compiled_code = '';
                // flag for aborting current and start recompile
                $this->abort_and_recompile = false;
                // get template source
                $_content = $this->template->source->content;
                if ($_content != '') {
                    // run prefilter if required
                    if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) {
                        $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
                    }
                    // call compiler
                    $_compiled_code = $this->doCompile($_content);
                }
            } while ($this->abort_and_recompile);
            if ($this->smarty->debugging) {
                Smarty_Internal_Debug::end_compile($this->template);
            }
        }
        // restore source
        $this->template->source = $save_source;
        unset($save_source);
        $this->smarty->_current_file = $this->template->source->filepath;
        // free memory
        unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template);
        self::$_tag_objects = array();
        // return compiled code to template object
        $merged_code = '';
        if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) {
            foreach ($this->merged_templates as $code) {
                $merged_code .= $code;
            }
        }
        // run postfilter if required on compiled template code
        if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') {
            $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template);
        }
        if ($this->suppressTemplatePropertyHeader) {
            $code = $_compiled_code . $merged_code;
        } else {
            $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code;
        }
        // unset content because template inheritance could have replace source with parent code
        unset ($template->source->content);

        return $code;
    }
397053
private function findTemplate($template)
    {
        $logicalName = (string) $template;

        if (isset($this->cache[$logicalName])) {
            return $this->cache[$logicalName];
        }

        $template = $this->templateNameParser->parse($template);
        $file = $this->templateLocator->locate($template);

        return $this->cache[$logicalName] = $file;
    }
624329
private function buildParts($template)
    {
        $template[0] = str_replace([
            '$NAMESPACE$',
            '$CLASS$',
            '$RULES$'
        ], [
            $this->namespace,
            'Create' . $this->className,
            $this->buildRules(0),
        ], $template[0]);

        $template[1] = str_replace([
            '$NAMESPACE$',
            '$CLASS$',
            '$RULES$'
        ], [
            $this->namespace,
            'Update' . $this->className,
            $this->buildRules(1),
        ], $template[1]);

        return $template;
    }
1035998
public function compile($template, $data)
    {
        foreach ($data as $key => $value) {
            $key = strtoupper($key);

            if(is_bool($value))
                $value = $value ? 'true' : 'false';

            $template = preg_replace("#\\$$key\\$#i", $value, $template);
        }

        return $template;
    }
86510
public static function start_compile($template)
    {
        static $_is_stringy = array('string' => true, 'eval' => true);
        if (!empty($template->compiler->trace_uid)) {
            $key = $template->compiler->trace_uid;
            if (!isset(self::$template_data[$key])) {
                if (isset($_is_stringy[$template->source->type])) {
                    self::$template_data[$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\'';
                } else {
                    self::$template_data[$key]['name'] = $template->source->filepath;
                }
                self::$template_data[$key]['compile_time'] = 0;
                self::$template_data[$key]['render_time'] = 0;
                self::$template_data[$key]['cache_time'] = 0;
            }
        } else {
            if (isset(self::$ignore_uid[$template->source->uid])) {
                return;
            }
            $key = self::get_key($template);
        }
        self::$template_data[$key]['start_time'] = microtime(true);
    }
276422
public function createTemplate(Template &$template)
		{
			$form_data = array(
				'template_name' => $template->getName(),
				'template_subject' => $template->getSubject(),
				'template_body_plain' => $template->getBodyPlain(),
				'template_body_html' => $template->getBodyHtml(),
				'template_body_mobile' => $template->getBodyMobile(),
				'charset' => $template->getCharacterSet(),
				'encoding' => $template->getCharacterEncoding(),
				'folder_id' => $template->getFolderId()
			);
			$data = $this->call('createtemplate', $form_data);

			$template->setTemplateId(trim($data[1]));

			//return $template;
		}
106691
private function resolveTemplate($template)
    {
        $template = str_replace(
            getcwd(),
            '',
            $this->viewResolver->resolve($template)
        );
        return $template;
    }
469033
protected function getTemplate($template)
    {
        $path = realpath(__DIR__.'/../templates/'.$template.'.txt');

        return $this->files->get($path);
    }
941603
protected function render(Template $template)
    {
        $presenter = $this->createPresenter($template->getPresenter());

        try {
            $arguments = $this->getArguments($presenter, $template);
            $this->logger->debug($arguments);
            $result = call_user_func_array($presenter, $arguments);
        } catch(Exception $e) {
            if ($this->throwRenderExceptions) {
                throw $e;
            }

            $this->logger->error($e->getMessage() .
                    "\n\nURL: " . URLUtils::fullUrl() .
                    "\n\nTemplate:\n" . print_r($template, true) .
                    (isset($arguments) ? "\n\n$presenter args:\n" . print_r($arguments, true) : '')
                );

            $result = '';
        }

        return $result;
    }
599459
public static function create_template($template) {
        global $PAGE;

        $params = self::validate_parameters(self::create_template_parameters(), array('template' => $template));
        $params = $params['template'];
        $context = self::get_context_from_params($params);
        self::validate_context($context);
        $output = $PAGE->get_renderer('core');

        unset($params['contextlevel']);
        unset($params['instanceid']);
        $params = (object) $params;
        $params->contextid = $context->id;

        $result = api::create_template($params);
        $exporter = new template_exporter($result);
        $record = $exporter->export($output);
        return $record;
    }
182873
public function compile($template, $data)
    {
        foreach ($data as $key => $value) {
            // TODO refactor code so that we do not need this check
            if (!is_string($value)) {
                continue;
            }

            $template = preg_replace("/\\$$key\\$/i", $value, $template);
        }

        return preg_replace('/(<?php)/', "$1\n" . $this->renderBanner(), $template, 1);
    }
543759
private function fetchTemplate($template)
    {
        $resolver = $this->getResolver();
        $content  = $resolver->resolve($template);

        if (! $content) {
            throw new Exception\TemplateNotFoundException('Template by name "' . $template . '" not found');
        }

        return $content;
    }
1044554
protected function isRoutableTemplate(Template $template)
    {
        $template_file = new \SplFileInfo($template->getFilename());

        $is_routable =
            ($this->unroutablePrefix !== substr($template_file->getBasename(), 0, strlen($this->unroutablePrefix)));

        return($is_routable);
    }
631363
public function render($template) {
		$environment = [
			'post' => $_POST,
			'get' => $_GET,
			'cookie' => $_COOKIE,
			'server' => $_SERVER,
		];

		$environment = array_merge($environment, $this->environment);

		if ($this->i18n_available === true and $this->translation !== null) {
			$environment['translation'] = $this->translation;
			$environment['language'] = $this->translation->language;
		}

		if (isset($_SESSION)) {
			$environment['session'] = $_SESSION;
		}
		$this->twig->setLoader($this->filesystem_loader);
		$this->twig->addGlobal('env', $environment);
		return $this->twig->render($template, $this->variables);
	}
1272045
public static function start_compile($template)
    {
        $key = self::get_key($template);
        self::$template_data[$key]['start_time'] = microtime(true);
    }
811148
public function render($template, array $context = array())
    {
        $template = $this->twig->createTemplate($template);

        return $template->render($context);
    }