@param string $template
@param array  $placeholders

@return string
555136
public function translate($template, $placeholders = null)
    {
        $context = $this->_context;

        $locale = $context->locale ?: $this->getLocale();

        if ($pos = strpos($locale, '-')) {
            $fallback = substr($locale, 0, $pos);
        } else {
            $fallback = null;
        }

        if ($this->_messages === null) {
            foreach ($this->_files as $file) {
                $messages = [];
                $file = $this->alias->resolve("$file/$locale.php");
                if (is_file($file)) {
                    /** @noinspection PhpIncludeInspection */
                    $messages = require $file;
                } elseif ($fallback) {
                    $file = $this->alias->resolve("$file/$fallback.php");
                    if (is_file($file)) {
                        /** @noinspection PhpIncludeInspection */
                        $messages = require $file;
                    }
                }

                if ($messages) {
                    if ($this->_messages) {
                        /** @noinspection SlowArrayOperationsInLoopInspection */
                        $this->_messages = array_merge($this->_messages, $messages);
                    } else {
                        $this->_messages = $messages;
                    }
                }
            }
        }

        $message = isset($this->_messages[$template]) ? $this->_messages[$template] : $template;

        if ($placeholders) {
            $replaces = [];

            if (strpos($message, ':') !== false) {
                foreach ($placeholders as $k => $v) {
                    $replaces[':' . $k] = $v;
                }
            }

            if (strpos($message, '{') !== false) {
                foreach ($placeholders as $k => $v) {
                    $replaces['{' . $k . '}'] = $v;
                }
            }

            return strtr($message, $replaces);
        } else {
            return $message;
        }
    }
799827
private function translate(string $template, array $parameters): string
    {
        $placeholders = array_map([$this, 'getPlaceholder'], array_keys($parameters));
        $replacements = array_map([$this, 'getTranslatedValue'], array_values($parameters));

        return str_replace($placeholders, $replacements, $template);
    }
274223
public function renderTemplate(string $template, array $variables = []): string
    {
        return $this->renderTemplateString($this->getTemplate($template), $variables);
    }
320946
protected function render($templateName, array $placeholderValuePairs)
    {
        $resultString = Messages::get($templateName);
        foreach ($placeholderValuePairs as $placeholder => $value) {
            $resultString = str_replace('{{ '.$placeholder.' }}', $value, $resultString);
        }

        return $resultString;
    }
138089
public static function replaceTpl($content, array $placeholders = null, Template $template)
    {
        $template = clone $template;
        $template->removeAllPlaceholders();

        return $template->replace($content, $placeholders);
    }
566462
public function findPlaceholders(array $placeholders = [], $recursive = false)
    {
        if (empty($placeholders)) {
            return [];
        }
        $result = [];
        foreach ($placeholders as $name => $value) {
            if (is_int($name)) {

                if ($this->existsPlaceholder($value)) {

                    $result[$this->_prepareNamePlaceholder($value)] = $this->getPlaceholder($value, false);
                } elseif ($recursive) {
                    /** @var static $scope */
                    foreach (array_reverse($this->scopes, true) as $scope) {
                        if ($scope->existsPlaceholder($value)) {
                            $result[$this->_prepareNamePlaceholder($value)] = $scope->getPlaceholder($value);
                            break;
                        }
                    }
                }
                continue;
            }
            $result[$name] = $value;
        }

        return $result;
    }
70532
function replacePlaceholders(array $symbols, array $placeholders = array()) {
    $placeholders = array_merge(array(
      self::SYMBOL_SPECIAL_GROUPING_SEPARATOR,
      self::SYMBOL_SPECIAL_INFINITY,
      self::SYMBOL_SPECIAL_MINUS,
      self::SYMBOL_SPECIAL_NAN,
      self::SYMBOL_SPECIAL_PLUS,
    ), $placeholders);
    $replacements = array();
    foreach (array_unique($placeholders) as $placeholder) {
      $replacements[$placeholder] = $this->getReplacement($placeholder);
    }
    foreach ($symbols as $symbol) {
      foreach ($replacements as $placeholder => $replacement) {
        if (!$symbol->replacement && $symbol->symbol == $placeholder) {
          $symbol->replacement = $replacement;
        }
      }
    }
  }
1002336
public function render($context = null)
    {
        try {
            return $this->_render($context);
        } catch (InvalidArgumentException $e) {
            throw $e;
        } catch (RootException $e) {
            throw $this->_createTemplateRenderException($this->__('Could not render placeholder template'), null, $e, $this, $context);
        }
    }
1330254
private function replaceVariables($template, array $variables): string
    {
        foreach ($variables as $key => $value) {
            $key = '%'.$key.'%';

            $template = \str_replace($key, $value, $template);
        }

        return $template;
    }
233546
public static function iempty($value = null, array $params, Template $template)
    {
        if (!empty($value)) {
            return $value;
        }
        $template = clone $template;
        $placeholders = array_merge(
            !empty($params['addPlaceholders']) ? $template->findPlaceholders($params['addPlaceholders']) : [],
            ['output' => $value]
        );

        return $template->replace($params['then'], $placeholders);
    }
94810
protected function echos(string $template): string
	{
		// Closure that matches the "empty else" syntax

		$emptyElse = function($matches)
		{
			if(preg_match('/(.*)((\|\|)|(\s+or\s+))(.+)/', $matches) !== 0)
			{
				return preg_replace_callback('/(.*)((\|\|)|(\s+or\s+))(.+)/', function($matches)
				{
					return '(empty(' . trim($matches[1]) . ') ? ' . trim($matches[5]) . ' : ' . trim($matches[1]) . ')';
				}, $matches);
			}

			return $matches;
		};

		// Compiles echo tags

		return preg_replace_callback('/{{\s*(.*?)\s*}}/', function($matches) use ($emptyElse)
		{
			if(preg_match('/raw\s*:(.*)/i', $matches[1]) > 0)
			{
				return sprintf('<?php echo %s; ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1)));
			}
			elseif(preg_match('/preserve\s*:(.*)/i', $matches[1]) > 0)
			{
				return sprintf('<?php echo $this->escapeHTML(%s, $__charset__, false); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1)));
			}
			elseif(preg_match('/attribute\s*:(.*)/i', $matches[1]) > 0)
			{
				return sprintf('<?php echo $this->escapeAttribute(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1)));
			}
			elseif(preg_match('/js\s*:(.*)/i', $matches[1]) > 0)
			{
				return sprintf('<?php echo $this->escapeJavascript(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1)));
			}
			elseif(preg_match('/css\s*:(.*)/i', $matches[1]) > 0)
			{
				return sprintf('<?php echo $this->escapeCSS(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1)));
			}
			elseif(preg_match('/url\s*:(.*)/i', $matches[1]) > 0)
			{
				return sprintf('<?php echo $this->escapeURL(%s, $__charset__); ?>', $emptyElse(substr($matches[1], strpos($matches[1], ':') + 1)));
			}
			else
			{
				return sprintf('<?php echo $this->escapeHTML(%s, $__charset__); ?>', $emptyElse($matches[1]));
			}
		}, $template);
	}
533624
private function getPlaceholders($navItemPageId, $placeholderVar, $prevId)
    {
        return (new Query())
            ->from('cms_nav_item_page_block_item t1')
            ->select(['t1.id', 't1.block_id', 't1.json_config_values', 't1.json_config_cfg_values', 't1.variation', 't2.class'])
            ->innerJoin('cms_block t2', 't2.id=t1.block_id')
            ->where(['nav_item_page_id' => $navItemPageId, 'placeholder_var' => $placeholderVar, 'prev_id' => $prevId, 'is_hidden' => 0])
            ->orderBy(['sort_index' => SORT_ASC])
            ->all();
    }
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);
    }
254565
private function getTranslation($message, array $placeholders)
    {
        if ($this->translator->has($message)) {
            $message = $this->translator->get($message, $placeholders);
        }

        return $message;
    }
1244530
def get_placeholders(template_name):
    
    dummy_context.template = template.Template("")
    try:
        temp_wrapper = template.loader.get_template(template_name)
    except template.TemplateDoesNotExist:
        return []

    plist, blist = [], []
    temp = temp_wrapper.template
    _placeholders_recursif(temp.nodelist, plist, blist)

    previous = {}
    block_to_remove = []
    for block in blist:
        if block.name in previous:
            if not hasattr(block, 'has_super_var'):
                block_to_remove.append(previous[block.name])
        previous[block.name] = block

    def keep(p):
        return p.found_in_block not in block_to_remove

    placeholders = [p for p in plist if keep(p)]
    names = []
    pfiltered = []
    for p in placeholders:
        if p.ctype not in names:
            pfiltered.append(p)
            names.append(p.ctype)

    return pfiltered
973752
public function Lexer($template, $output = array(), $position = 0)
    {
        $output = $this->PregCapture($template, $output, $position);

        $length = strlen($template);
        $lex = array();
        $lex['text'] = substr($template, $position, $length);
        $lex['start'] = $position;
        $lex['end'] = $length;
        $lex['length'] = ($length - $position);
        $lex['flag'] = false;
        $lex['inverse'] = false;
        $lex['key'] = false;
        $lex['param'] = false;

        $output[] = $lex;

        return $output;
    }
982833
protected static function textInsertion($template, array $data)
    {
        $replacements = [];
        foreach($data as $key => $value)
        {
            $replacements['{{' . $key . '}}'] = $value;
        }

        return strtr($template, $replacements);
    }