Render a string from the Messages library.

@param string $templateName          Name of template
@param array  $placeholderValuePairs Associative array of substitute values

@return string
320946
protected function render($templateName, array $placeholderValuePairs)
    {
        $resultString = Messages::get($templateName);
        foreach ($placeholderValuePairs as $placeholder => $value) {
            $resultString = str_replace('{{ '.$placeholder.' }}', $value, $resultString);
        }

        return $resultString;
    }
732036
public function apply(&$templateString) {

		$application	= Application::getInstance();
		$config			= $application->getConfig();

		$locale = $application->getCurrentLocale();

		// without locale replace placeholders with their identifier

		if(empty($locale)) {

			$templateString = preg_replace(
				array(
					'@\{![a-z0-9_]+\}@i',
					'@\{![a-z0-9_]+:(.*?)\}@i'
				),
				array(
					'',
					'$1'
				),
				$templateString
			);
			return;

		}

		$this->getPhrases($locale);

		$templateString = preg_replace_callback(
			'@\{!([a-z0-9_]+)(:(.*?))?\}@i',
			array($this, 'translatePhraseCallback'),
			$templateString
		);
	}
1760
public function renderValue(array $context, $value, array $parameters = [], ?string $viewContext = null): string
    {
        try {
            return $this->renderer->renderValue(
                $value,
                $this->getViewContext($context, $viewContext),
                $parameters
            );
        } catch (Throwable $t) {
            $message = sprintf(
                'Error rendering a value of type "%s"',
                is_object($value) ? get_class($value) : gettype($value)
            );

            $this->errorHandler->handleError($t, $message, ['object' => $value]);
        }

        return '';
    }
329606
protected function evaluatePHP($strFilename, $mixArgumentArray, &$templateSettings = null)
    {
        // Get all the arguments and set them locally
        if ($mixArgumentArray) {
            foreach ($mixArgumentArray as $strName => $mixValue) {
                $$strName = $mixValue;
            }
        }
        global $_TEMPLATE_SETTINGS;
        unset($_TEMPLATE_SETTINGS);
        $_TEMPLATE_SETTINGS = null;

        // Of course, we also need to locally allow "objCodeGen"
        $objCodeGen = $this;

        // Get Database Escape Identifiers
        $strEscapeIdentifierBegin = \QCubed\Database\Service::getDatabase($this->intDatabaseIndex)->EscapeIdentifierBegin;
        $strEscapeIdentifierEnd = \QCubed\Database\Service::getDatabase($this->intDatabaseIndex)->EscapeIdentifierEnd;

        // Store the Output Buffer locally
        $strAlreadyRendered = ob_get_contents();

        if (ob_get_level()) {
            ob_clean();
        }
        ob_start();
        include($strFilename);
        $strTemplate = ob_get_contents();
        ob_end_clean();

        $templateSettings = $_TEMPLATE_SETTINGS;
        unset($_TEMPLATE_SETTINGS);

        // Restore the output buffer and return evaluated template
        print($strAlreadyRendered);

        // Remove all \r from the template (for Win/*nix compatibility)
        $strTemplate = str_replace("\r", '', $strTemplate);
        return $strTemplate;
    }
631885
public function render($templateName = null, $data = [])
    {
        $this->setTemplate($templateName, $data);

        return json_encode($this->_data);
    }
115560
public function getTemplate($templateTypeName, $placeholders = [], $locale = null, $mode = 'content')
    {
        $parameters = $this->serializer->serialize([Options::SERIALIZE_MINIMAL]);
        $result = '';
        $templateType = $this->templateTypeRepo->findOneBy(['name' => $templateTypeName]);

        // Checks if a template is associated to the template type
        if ($templateType && $templateType->getDefaultTemplate()) {
            $template = null;

            // Fetches template for the given type and locale
            if ($locale) {
                $template = $this->templateRepo->findOneBy([
                    'type' => $templateType,
                    'name' => $templateType->getDefaultTemplate(),
                    'lang' => $locale,
                ]);
            }
            // If no template is found for the given locale or locale is null, uses default locale
            if (!$locale || !$template) {
                $defaultLocale = isset($parameters['locale']['default']) ? $parameters['locales']['default'] : null;

                if ($defaultLocale && $defaultLocale !== $locale) {
                    $template = $this->templateRepo->findOneBy([
                        'type' => $templateType,
                        'name' => $templateType->getDefaultTemplate(),
                        'lang' => $defaultLocale,
                    ]);
                }
            }
            // If a template is found
            if ($template) {
                switch ($mode) {
                    case 'content':
                        $result = $this->replacePlaceholders($template->getContent(), $placeholders);
                        break;
                    case 'title':
                        $result = $template->getTitle() ?
                            $this->replacePlaceholders($template->getTitle(), $placeholders) :
                            '';
                        break;
                }
            }
        }

        return $result;
    }
1272830
public function render(string $view, array $templateVars = []): string
    {
        return $this->renderer->render($view, $templateVars);
    }
918322
private function render($templateString, array $data)
    {
        $snippetRenderer = \TPkgSnippetRenderer::GetNewInstance(
            $templateString,
            \IPkgSnippetRenderer::SOURCE_TYPE_STRING
        );
        foreach ($data as $key => $value) {
            $snippetRenderer->setVar($key, $value);
        }

        return trim($snippetRenderer->render());
    }
667617
public function render($templateName = null)
    {
        if ($templateName === null) {
            throw new InvalidArgumentException(
                'An template name is required and will be search relative from configured templates path'
            );
        }
        $this->setTemplateName($templateName);

        return parent::render($templateName);
    }
319480
public function getTemplateVar($templateVariableName)
    {
        if (! isset($this->templateVars[$templateVariableName])) {
            throw new \InvalidArgumentException(sprintf("Template variable '%s' is not defined.", $templateVariableName));
        }

        return $this->templateVars[$templateVariableName];
    }
141519
public function replace(array $placeholders = [])
    {
        if (empty($placeholders)) {
            return $this;
        }
        $callback = function ($value) use ($placeholders) {
            return StringHelper::replace($value, $placeholders, false);
        };
        $this->data = ArrayHelper::map($this->data, $callback, true);
        return $this;
    }
167098
protected function renderTpl()
    {
        if (empty($this->tpl)) {
            return Json::encode($this->array);
        }
        $i = 1;
        $result = '';
        $countItems = count($this->array);
        $addPlaceholders = $this->template->findPlaceholders($this->addPlaceholders);
        $addPlaceholders['countItems'] = $countItems;
        $placeholders = [];

        foreach ($this->array as $placeholders) {
            if (is_array($placeholders)) {
                $placeholders['currentItem'] = $i;
                $this->prepareItem($placeholders);
                $result .= $this->template->replaceByPrefix(
                    $this->tpl,
                    array_merge($placeholders, $addPlaceholders)
                );
                ++$i;
                continue;
            }
            $result .= $this->template->replaceByPrefix(
                $this->tpl,
                array_merge($addPlaceholders, ['output' => $placeholders, 'currentItem' => $i]));

            ++$i;
        }

        // Deleting placeholders
        if (is_array($placeholders)) {
            $this->template->removeMultiPlaceholders(array_keys($placeholders));
        }
        // Inserting content into wrapper template (optional)
        if (!empty($this->wrapperTpl)) {
            $result = $this->renderWrapperTpl($result, $addPlaceholders);
        }
        // Concat pagination
        if (empty($this->pagination['toPlaceholder'])) {
            $result .= $this->template->getPlaceholder('pagination', false);
        }
        // Deleting placeholders
        $this->template->removePlaceholder('pagination');
        $this->template->removeMultiPlaceholders(array_keys($addPlaceholders));
        // To placeholder
        if (!empty($this->toPlaceholder)) {
            $this->template->addPlaceholder($this->toPlaceholder, $result, true);
            $this->template->cachePlaceholders[$this->toPlaceholder] = $result;
            return null;
        }

        return $result;
    }
1141501
protected function interpolate($message, array $placeholders = [])
    {
        if ($placeholders) {
            $replace = [];
            foreach ($placeholders as $key => $val) {
                $replace['{' . $key . '}'] = $val;
            }

            return strtr($message, $replace);
        } else {
            return $message;
        }
    }
254565
private function getTranslation($message, array $placeholders)
    {
        if ($this->translator->has($message)) {
            $message = $this->translator->get($message, $placeholders);
        }

        return $message;
    }
254423
public static function notEmpty($value, array $params, Template $template)
    {
        if (empty($value)) {
            return '';
        }
        //$template = clone $template;
        $placeholders = array_merge(
            !empty($params['addPlaceholders']) ? $template->findPlaceholders($params['addPlaceholders']) : [],
            ['output' => $value]
        );
        return $template->replaceByPrefix($params['then'], $placeholders);
    }
1029440
private function renderBlock(array $blockNames, $cacheKey, array $context)
    {
        $template = $blockName = null;

        $themes = $this->defaultThemes;
        if (isset($this->themes[$cacheKey])) {
            $themes = array_merge($this->themes[$cacheKey], $this->defaultThemes);
        }

        // Search the template for first block available
        foreach ($blockNames as $name) {
            if ($template = $this->getTemplateForBlock($name, $themes)) {
                $blockName = $name;
                break;
            }
        }

        // Throw if no matching blocks are found
        if (empty($template)) {
            throw new \RuntimeException(sprintf(
                "Block%s %s not found in table themes (%s)",
                count($blockNames) > 1 ? 's' : '', implode(', ', $blockNames), implode(', ', $this->defaultThemes)
            ));
        }

        return $template->renderBlock($blockName, $context);
    }
611343
protected function placeholderResolver()
    {
        if (null === $this->placeholderResolver) {
            $this->placeholderResolver = new RegexPlaceholderResolver(new ConfigurationDataSource($this), '%', '%');
        }

        return $this->placeholderResolver;
    }