Fetches template with previous set data.

@param Request $request
@param string  $template The template to render

@return string
@throws Exception
11259
public function fetchTemplate(Request $request, $template)
    {
        if (!$this->view instanceof Twig) {
            throw new Exception("Twig provider not registered.");
        }

        foreach ($this->settings['view']['global'] as $key => $map) {
            $key = is_numeric($key) ? $map : $key;

            switch ($key) {
                case 'request':
                    $value = $request;
                    break;

                default:
                    $value = isset($this->container[$key]) ? $this->container[$key] : null;
                    break;
            }

            $this->view->getEnvironment()->addGlobal($map, $value);
        }

        $result = $this->view->fetch(
            $template . $this->settings['view']['extension'],
            $this->data->all()
        );

        return $result;
    }
1171284
protected function getPathToTemplates($template = null)
    {
        $template = Helpers::getPathWithSlash($template ?: Config::getDefaultTemplateName());
        $basePath = base_path(Config::getTemplatesPath() . $template);
        $path = Helpers::getPathWithSlash($basePath);

        if (!$this->isFileExists($path)) {
            throw new Exception('Invalid template. Make sure the following path exists: "' . $path . '"');
        }

        return $path;
    }
579902
public function webPreViewAction(Request $request, $template, $format = null)
    {
        if ('txt' !== $format) {
            $format = 'html';
        }

        $template = urldecode($template);

        $locale = $request->getLocale();

        // merge request vars with dummyVars, but make sure request vars remain as they are.
        $emailVars = array_merge(array(), $request->query->all());
        $emailVars = $this->get('azine_email_web_view_service')->getDummyVarsFor($template, $locale, $emailVars);
        $emailVars = array_merge($emailVars, $request->query->all());

        // add the styles
        $emailVars = $this->getTemplateProviderService()->addTemplateVariablesFor($template, $emailVars);

        // add the from-email for the footer-text
        if (!array_key_exists('fromEmail', $emailVars)) {
            $noReply = $this->getParameter('azine_email_no_reply');
            $emailVars['fromEmail'] = $noReply['email'];
            $emailVars['fromName'] = $noReply['name'];
        }

        // set the emailLocale for the templates
        $emailVars['emailLocale'] = $locale;

        // replace absolute image-paths with relative ones.
        $emailVars = $this->getTemplateProviderService()->makeImagePathsWebRelative($emailVars, $locale);

        // add code-snippets
        $emailVars = $this->getTemplateProviderService()->addTemplateSnippetsWithImagesFor($template, $emailVars, $locale);

        // render & return email
        $response = $this->renderResponse("$template.$format.twig", $emailVars);

        // add campaign tracking params
        $campaignParams = $this->getTemplateProviderService()->getCampaignParamsFor($template, $emailVars);
        $campaignParams['utm_medium'] = 'webPreview';
        if (sizeof($campaignParams) > 0) {
            $htmlBody = $response->getContent();
            $htmlBody = $this->get('azine.email.bundle.twig.filters')->addCampaignParamsToAllUrls($htmlBody, $campaignParams);

            $emailOpenTrackingCodeBuilder = $this->get('azine_email_email_open_tracking_code_builder');
            if ($emailOpenTrackingCodeBuilder) {
                // add an image at the end of the html tag with the tracking-params to track email-opens
                $imgTrackingCode = $emailOpenTrackingCodeBuilder->getTrackingImgCode($template, $campaignParams, $emailVars, 'dummy', 'dummy@from.email.com', null, null);
                if ($imgTrackingCode && strlen($imgTrackingCode) > 0) {
                    // replace the tracking url, so no request is made to the real tracking system.
                    $imgTrackingCode = str_replace('://', '://webview-dummy-domain.', $imgTrackingCode);
                    $htmlCloseTagPosition = strpos($htmlBody, '</html>');
                    $htmlBody = substr_replace($htmlBody, $imgTrackingCode, $htmlCloseTagPosition, 0);
                }
            }
            $response->setContent($htmlBody);
        }

        // if the requested format is txt, remove the html-part
        if ('txt' == $format) {
            // set the correct content-type
            $response->headers->set('Content-Type', 'text/plain');

            // cut away the html-part
            $content = $response->getContent();
            $textEnd = stripos($content, '<!doctype');
            $response->setContent(substr($content, 0, $textEnd));
        }

        return $response;
    }
1255093
private function _renderTemplate($template = null)
    {
        // when no template, auto generate template path.
        // View/Content/[controller]/[action].html.twig
        $def = $this->actionChain->getCurrentAction();
        if (! $template) {
            $controller = join(DS, array_map('ucfirst', explode('_', $def['controller_name'])));
            $action = $def['action'];
            $template = sprintf('%s/%s.%s', $controller, substr($this->actionChain->actionNameStrategy($action), 0, -6), $this->renderer->getSuffix());
        }

        // rendering by renderer.
        $def['controller']->beforeRenderer();
        $result = $this->renderer->render($template);
        $this->response->setBody($result);
        if ($this->response->isHttp()) {
            $this->response->setHeader('content-type', sprintf('text/html; charset=%s', $this->application->config('encoding.output')));
        }
    }
279556
public function setTemplate($template)
    {
        $updateTemplateStm = $this->connection->prepare("UPDATE Page SET template = :template WHERE page_id = :page_id");
        $updateTemplateStm->bindParam(":template", $this->template);
        $updateTemplateStm->bindParam(":page_id", $this->page_id);
        $this->template = $template;
        $updateTemplateStm->execute();
    }
603765
public function retrieveCurrent(Request $request)
    {
        if (ConfigQuery::isRewritingEnable()) {
            $view = $request->attributes->get('_view', null);

            $viewLocale = $this->getViewLocale($request);

            $viewId = $view === null ? null : $request->query->get($view . '_id', null);

            $allOtherParameters = $request->query->all();
            if ($view !== null) {
                unset($allOtherParameters['view']);
                if ($viewId !== null) {
                    unset($allOtherParameters[$view . '_id']);
                }
            }
            if ($viewLocale !== null) {
                unset($allOtherParameters['lang']);
                unset($allOtherParameters['locale']);
            }

            $this->retriever->loadSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters);
        } else {
            $allParametersWithoutView = $request->query->all();
            $view = $request->attributes->get('_view');
            if (isset($allOtherParameters['view'])) {
                unset($allOtherParameters['view']);
            }
            $this->retriever->rewrittenUrl = null;
            $this->retriever->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView);
        }

        return $this->retriever;
    }
972104
public function render($request, Exception $exception)
    {
        $exception = $this->prepareException($exception);

        if ($exception instanceof HttpResponseException) {
            return $exception->getResponse();
        } elseif ($exception instanceof AuthenticationException) {
            return $this->unauthenticated($request, $exception);
        } elseif ($exception instanceof ValidationException) {
            return $this->convertValidationExceptionToResponse($exception, $request);
        } elseif ($this->isHttpException($exception) && $this->customErrorHtmlTemplateExists($exception)) {
            return $this->prepareResponse($request, $exception);
        }

        $flattened = FlattenException::create($exception);

        $code = $flattened->getStatusCode();
        $headers = $flattened->getHeaders();
        $response = $this->getContent($exception, $code, $request);

        // If it's already a response, return that.
        if (!$response instanceof BaseResponse) {
            $response = new Response($this->getContent($exception, $code, $request), $code, $headers);
        }

        return $response;
    }
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;
    }
978739
public static function load($template)
	{
		$dom = self::loadAsXML($template) ?: self::loadAsXML(self::fixEntities($template));
		if ($dom)
		{
			return $dom;
		}

		// If the template contains an XSL element, abort now. Otherwise, try reparsing it as HTML
		if (strpos($template, '<xsl:') !== false)
		{
			$error = libxml_get_last_error();

			throw new RuntimeException('Invalid XSL: ' . $error->message);
		}

		return self::loadAsHTML($template);
	}
356909
public function renderString(string $template, array $data = [])
    {
        try {
            return $this->loadFromString($template)->render($data);
        } catch (SyntaxError $e) {
            if ($this->exceptionHandler) {
                $e->setTemplateContent($template);

                return $this->renderSyntaxError($e);
            } else {
                throw $e;
            }
        }
    }
1146406
public function render($request, Exception $exception)
    {
        // Convert all non-http exceptions to a proper 500 http exception
        // if we don't do this exceptions are shown as a default template
        // instead of our own view in resources/views/errors/500.blade.php
        if ($this->shouldReport($exception) && !$this->isHttpException($exception) && !config('app.debug')) {
            $exception = new HttpException(500, 'Whoops!');
        }

        return parent::render($request, $exception);
    }
837038
public function getTemplateQuery($template)
    {
        if(isset($this->template[$template]))
        {
            return $this->template[$template];
        }

        return FALSE;
    }
865434
protected function findTemplate(Request $request, $format, $code, $showException)
    {
        $name = $showException ? 'exception' : 'error';
        if ($showException && 'html' == $format) {
            $name = 'exception_full';
        }

        // For error pages, try to find a template for the specific HTTP status code and format
        if (!$showException) {
            $template = sprintf('@Twig/Exception/%s%s.%s.twig', $name, $code, $format);
            if ($this->templateExists($template)) {
                return $template;
            }
        }

        // try to find a template for the given format
        $template = sprintf('@Twig/Exception/%s.%s.twig', $name, $format);
        if ($this->templateExists($template)) {
            return $template;
        }

        // default to a generic HTML exception
        $request->setRequestFormat('html');

        return sprintf('@Twig/Exception/%s.html.twig', $showException ? 'exception_full' : $name);
    }
1212528
private function updateMessageTemplate( $template, $key ) {    
        //invalide message key
        if( !key_exists( $messageKey, $this->templates ) && $key != self::DEFAULT_KEY )
            throw new Exception\MessageTemplateDoesNotExist( "A message template does not exist for key $messageKey" );

        $this->templates[$key] = $template;
    }
106691
private function resolveTemplate($template)
    {
        $template = str_replace(
            getcwd(),
            '',
            $this->viewResolver->resolve($template)
        );
        return $template;
    }
1355244
public function show(Request $request)
    {
        $count = $request->query->get('count', \Bolt\Stack::MAX_ITEMS);
        $options = $request->query->get('options');

        if ($options === 'ck') {
            $template = '@bolt/components/stack/ck.twig';
        } elseif ($options === 'list') {
            $template = '@bolt/components/stack/list.twig';
        } else {
            $template = '@bolt/components/stack/panel.twig';
        }

        $context = [
            'count'     => $count,
            'filetypes' => $this->getOption('general/accept_file_types'),
            'namespace' => $this->app['upload.namespace'],
            'canUpload' => $this->isAllowed('files:uploads'),
        ];

        return $this->render($template, ['context' => $context]);
    }
293792
private function fetch(string $template): string
    {
        try {
            $result = $this->smarty->fetch($template);
        } catch (SmartyException $exception) {
            throw new InvalidMarkup($exception->getMessage());
        } catch (Exception $exception) {
            throw new InvalidMarkup($exception->getMessage());
        }

        return $result;
    }