Generate content from static template compilation

@param string $template
@param array $vars
@param array $blocks
@return string
5247
public static function make($template, array $vars = [], array $blocks = [])
    {
        if(!static::$instance) {
            static::$instance = new static;
        }

        return static::$instance->render($template, $vars, $blocks);
    }
1367006
public function render($template = '', $data = []) {
		if (!isset($this->blocks[$template])) {
			$this->blocks[$template] = $this->blockFactory->create($template);
		}
		$block = $this->blocks[$template];
		$block->setData($data);
		return $block->render();
	}
149254
public static function expand($template, array $variables)
    {
        if (strpos($template, '{') === false) {
            return $template;
        }

        self::$variables = $variables;

        return preg_replace_callback('/\{([^\}]+)\}/', [UriTemplate::class, 'expandMatch'], $template);
    }
661795
protected function makeResponse(string $template, array $vars = [])
    {
        if (request()->ajax()) {
            return $this->jsonOutput($vars);
        }

        return $this->renderOutput($template, $vars);
    }
800323
protected static function with(&$context, $vars) {
        $v = isset($vars[1]) ? static::getVariableNameOrSubExpression($context, $vars[1]) : array(null, array());
        $bp = Parser::getBlockParams($vars);
        $bs = $bp ? ('array(' . Expression::listString($bp) . ')') : 'null';
        $be = $bp ? " as |$bp[0]|" : '';
        return $context['ops']['seperator'] . static::getFuncName($context, 'wi', 'with ' . $v[1] . $be) . "\$cx, {$v[0]}, $bs, \$in, function(\$cx, \$in) {{$context['ops']['array_check']}{$context['ops']['f_start']}";
    }
351270
public function renderString($template, array $params = null)
    {
        if (! empty($params)) {
            $this->assign($params);
        }

        $compiled = $this->getCompiler()->compile($template);

        $tempFile = tempnam(sys_get_temp_dir(), __FUNCTION__);

        $this->writeToFile($tempFile, $compiled);

        $template = $this->readBuffer($tempFile);

        unlink($tempFile);

        return $template;
    }
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 );
	}
1259684
public function addTemplate($template, $vars = []) {
        $tpl = new Template($template, 'template-mail', 0);

        foreach ($vars as $key => $var) {
            $tpl->assign($key, $var);
        }

        $message = $tpl->show();
        array_push($this->_message, $message);
    }
1001852
public function renderTemplateString(string $template, array $variables = []): string
    {
        $output = $this->indexControlStructure($template, 'foreach');
        $output = $this->indexControlStructure($output, 'if', ['else']);

        $output = $this->resolveLoops($output, $variables);
        $output = $this->resolveConditionals($output, $variables);

        return $this->replaceVariablesInTemplate($output, $variables);
    }
523578
public function render($template, $variables, $default = false)
    {
        if ($default) {
            $template = $this->homeService->defaultTemplate($template);
        }

        return new Response($this->templating->render($template, $variables));
    }
1372952
public function getBlockFromTemplate($twig, $template, $block, $vars = [])
    {
        return $twig
            ->loadTemplate($template)
            ->renderBlock($block, $vars)
        ;
    }
1033950
protected function render(string $template, array $vars = [])
    {
        $vars['flash'] = $this->flash;
        $this->view->setVars($vars);

        $content = $this->view->render($template);
        $this->response->setContent($content);

        return $this->response;
    }
1230379
public function render($vars = [], $asc = 0)
	{
		$vars = $this->vars + $vars;
		$className = get_called_class();

		while($asc > 0)
		{
			$parentClass = get_parent_class($className);

			if(!$parentClass)
			{
				break;
			}

			$className = $parentClass;

			$asc--;
		}

		do {
			$reflection = new \ReflectionClass($className);
			$classFile = $reflection->getFileName();

			$fileContent = file_get_contents($classFile);
			$tokens = token_get_all($fileContent);
			$hasHalt = FALSE;

			foreach($tokens as $token)
			{
				if(is_array($token)
					&& isset($token[0], $token[2])
				) {
					if($token[0] == T_HALT_COMPILER)
					{
						$hasHalt = TRUE;
						$this->haltLine = $token[2] - 1;
					}
				}
			}

			if($hasHalt)
			{
				$template = $tokens[ count($tokens)-1 ][1];
				break;
			}

			$className = get_parent_class($className);
    
			if(!$className || $className == get_class())
			{
				throw new \Exception(sprintf(
					'Cannot locate template. '
					. 'No call to __halt_compiler() found along inheritance chain of %s.'
					, get_called_class()
				));
			}

		} while(!$hasHalt);

		$renderScope = \Closure::Bind(
			function() use($template, $vars, $classFile)
			{
				extract($vars);
				ob_start();

				try{
					eval($template);
				}
				catch(\Exception $e)
				{
					error_log(
						'Exception thrown in template: '
							. $classFile
							. ':'
							. ($e->getLine() + $this->haltLine)
							. PHP_EOL
							. $e->getMessage()
					);

					throw $e;
				}

				$content = ob_get_contents();
				ob_end_clean();

				return $content;
			}
			, $this
			, get_called_class()
		);

		$result = $renderScope();

		if(isset($vars['__debug']) && $vars['__debug'])
		{
			$result = sprintf(
				"<!-- START %s -->\n%s\n<!-- END %s --->"
				, get_called_class()
				, $result
				, get_called_class()
			);
		}

		return $result;
	}
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)));
            }
        }
    }
692351
public function renderBlock(Twig_Environment $env, $template, $block, $context)
    {
        $template = $env->loadTemplate($template);
        $context = $env->mergeGlobals($context);

        return $template->renderBlock($block, $context);
    }
520673
public function renderInitCmsBlock($template, LayoutBlockInterface $layoutBlock, $params = [])
    {
        if (!$serializedContent = $layoutBlock->getSnapshotContent()) {
            // Draft View
            $contentItem = $layoutBlock->getContent();
        } else {
            // Live View
            $contentItem = $this->serializer->deserialize(
                $serializedContent,
                $layoutBlock->getClassType(),
                'json'
            );
        }

        if (!is_object($contentItem)) {
            $this->layoutBlockAdmin->delete($layoutBlock);

            return '---';
        }

        $options = $contentItem->getTemplateOptions($params);

        $options = array_merge($options, $params);

        return $this->templating->render($template, $options);
    }
307590
protected function renderOutput(string $template, array $vars = [])
    {
        $vars = array_merge($vars, [
            'unpublished' => Article::select(['id', 'user_id', 'state'])
            ->when('owner' != user('role'), function ($query) {
                // Show unpublished articles only to current user.
                $query->where('user_id', user('id'));
            })
            ->where('state', '<>', 'published')
            ->get(),
        ]);

        return parent::renderOutput($template, $vars);
    }