Fills the given $template array with values from the $source array

@param array $template the array to be filled
@param array $source the array to fetch values from

@return array Returns a filled version of $template
962811
public static function fillIfKeysExist(array $template, array $source)
    {
        $result = $template;
        foreach ($template as $key => $value) {
            if (array_key_exists($key, $source)) {
                $result[$key] = $source[$key];
            }
        }

        return $result;
    }
795353
protected function fillTemplate($template, Model $model)
    {
        $template = str_replace('{{namespace}}', $model->getBaseNamespace(), $template);
        $template = str_replace('{{class}}', $model->getClassName(), $template);

        $properties = $this->properties($model);
        $usedClasses = $this->extractUsedClasses($properties);
        $template = str_replace('{{properties}}', $properties, $template);

        $parentClass = $model->getParentClass();
        $usedClasses = array_merge($usedClasses, $this->extractUsedClasses($parentClass));
        $template = str_replace('{{parent}}', $parentClass, $template);

        $body = $this->body($model);
        $usedClasses = array_merge($usedClasses, $this->extractUsedClasses($body));
        $template = str_replace('{{body}}', $body, $template);

        $usedClasses = array_unique($usedClasses);
        $usedClassesSection = $this->formatUsedClasses(
            $model->getBaseNamespace(),
            $usedClasses
        );
        $template = str_replace('{{imports}}', $usedClassesSection, $template);

        return $template;
    }
1292894
public function populateTimestamp(Smarty_Template_Source $source)
    {
        $source->timestamp = $this->getTemplateTimestamp($source);
        $source->exists = !!$source->timestamp;
    }
105706
public static function _getDefaultTemplate(Smarty_Template_Source $source)
    {
        if ($source->isConfig) {
            $default_handler = $source->smarty->default_config_handler_func;
        } else {
            $default_handler = $source->smarty->default_template_handler_func;
        }
        $_content = $_timestamp = null;
        $_return = call_user_func_array($default_handler, array($source->type, $source->name, &$_content, &$_timestamp,
                                                                $source->smarty));
        if (is_string($_return)) {
            $source->exists = is_file($_return);
            if ($source->exists) {
                $source->timestamp = filemtime($_return);
            }
            $source->filepath = $_return;
        } elseif ($_return === true) {
            $source->content = $_content;
            $source->timestamp = $_timestamp;
            $source->exists = true;
            $source->handler->recompiled = true;
            $source->filepath = false;
        }
    }
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);
    }
402320
public function loop($template, array $model = array())
    {
        $out = '';

        foreach ($model as $row) {
            $out .= $this->partial($template, $row);
        }

        return $out;
    }
1111041
public static function create(Template $template): self
    {
        $renderTemplateDirective = new self();

        $renderTemplateDirective->type     = self::TYPE;
        $renderTemplateDirective->template = $template;

        return $renderTemplateDirective;
    }
481633
public function load($template)
    {
        $template = $this->findFirstExistingTemplate($template);
        if (!isset($this->loadedTemplates[ $template ])) {
            $class = $this->getTemplateClassName($template);

            $this->loadedTemplates[ $template ] = new $class($this);
            if (!$this->loadedTemplates[ $template ] instanceof Template) {
                throw new TemplatingException("The compiled class for {$template} is invalid");
            }
        }

        return $this->loadedTemplates[ $template ];
    }
1310056
public function getContent(Smarty_Template_Source $source)
    {
        if ($source->timestamp) {
            return file_get_contents($source->filepath);
        }
        if ($source instanceof Smarty_Config_Source) {
            throw new SmartyException("Unable to read config {$source->type} '{$source->name}'");
        }
        throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
    }
732671
static function load($_template)
    {
        // check runtime cache
        if (!$_template->source->handler->recompiled &&
            ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)
        ) {
            $_cache_key = $_template->source->unique_resource . '#';
            if ($_template->caching) {
                $_cache_key .= 'caching#';
            }
            $_cache_key .= $_template->compile_id;
            if (isset($_template->source->compileds[$_cache_key])) {
                return $_template->source->compileds[$_cache_key];
            }
        }
        $compiled = new Smarty_Template_Compiled();
        if ($_template->source->handler->hasCompiledHandler) {
            $_template->source->handler->populateCompiledFilepath($compiled, $_template);
        } else {
            $compiled->populateCompiledFilepath($_template);
        }
        // runtime cache
        if (!$_template->source->handler->recompiled &&
            ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)
        ) {
            $_template->source->compileds[$_cache_key] = $compiled;
        }
        return $compiled;
    }
22986
public static function parseTemplate($template, $data, $keepPlaceholders = false)
    {
        $t = $template;

        $hasMatches = preg_match_all("/[{]([^}]+)[}]/", $t, $matches);

        if ($hasMatches) {
            foreach ($matches[ 0 ] as $key => $match) {
                if (isset($data[$matches[1][$key]])) {
                    $template = str_replace($match, $data[$matches[1][$key]], $template);
                } else if (!$keepPlaceholders) {
                    $template = str_replace($match, '', $template);
                }
            }
        }

        return $template;
    }
157915
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
    {
        $source->filepath = $this->buildFilepath($source, $_template);

        if ($source->filepath !== false) {
            if (is_object($source->smarty->security_policy)) {
                $source->smarty->security_policy->isTrustedResourceDir($source->filepath);
            }

            $source->uid = sha1($source->filepath);
            if ($source->smarty->compile_check) {
                $source->timestamp = @filemtime($source->filepath);
                $source->exists = !!$source->timestamp;
            }
        }
    }
933682
protected function templateToString($template, array $data)
    {

        $templateFullName = $this->getTemplateFullName($template);

        if (!is_file($templateFullName)) {
            throw new RuntimeException("View cannot render `$template` because the template does not exist");
        }

        $fullData = array_merge($this->attributes, $data);
        $this->levelStartObcache = ob_get_level();
        $this->startSection($this->courentSection);
        $this->protectedIncludeScope($templateFullName, $fullData);
        $output = $this->endSection(true);
        $this->sectionContent[self::CONTENT] = $this->sectionContent[self::C_CONTENT];
        unset($this->sectionContent[self::C_CONTENT]);
        while (ob_get_level() > $this->levelStartObcache) {
            ob_end_clean();
        }

        if (!empty($this->layout)) {
            $layout = $this->layout;
            $this->layout = '';
            return $this->templateToString($layout, $fullData);
        }

        return $output;
    }
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;
    }
183875
public function setTemplate($template)
    {
        if(!$template instanceof TemplateInterface)
        {
            if(empty($template) || (is_string($template) && strpos($template, '.') === false) )
            {
                $identifier         = $this->getIdentifier()->toArray();
                $identifier['path'] = array('template');
                $identifier['name'] = $template;

                $identifier = $this->getIdentifier($identifier);
            }
            else $identifier = $this->getIdentifier($template);

            $template = $identifier;
        }

        $this->__template = $template;

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

        return strtr($template, $replacements);
    }
351458
public function getTemplateContent($template, array $variables)
    {
        $dir = dirname($template);
        $file = basename($template);

        $twig = new \Twig_Environment(new \Twig_Loader_Filesystem(array($dir)), array(
            'debug'            => true,
            'cache'            => false,
            'strict_variables' => true,
            'autoescape'       => false,
        ));
        return $twig->render($file, $variables);
    }