Compile la template, ses sous templates et ses variables.

@return string La template compilée.
171949
public function render()
    {
        require_once 'functions_include.php';
        $block = [];
        foreach ($this->blocks as $key => &$subTpl) {
            $block[ $key ] = !is_null($subTpl)
                ? $this->filter('block.' . $key, $subTpl->render())
                : '';
        }

        foreach ($this->vars as $key => $value) {
            $$key = $this->filter('var.' . $key, $value);
        }

        ob_start();
        require $this->path . $this->name;
        $html = ob_get_clean();

        return $this->filter('output', $html);
    }
1334138
function compileTemplate( $tpl, $keyData, $uri, $res, $templatePath, &$extraParameters, &$resourceData )
    {
        $key = $this->cacheKey( $keyData, $res, $templatePath, $extraParameters );
        return eZTemplateCompiler::compileTemplate( $tpl, $key, $resourceData );
    }
116398
private function runTemplate()
    {
        if (!isset(Template::$complieCache[$this->tplId])) {
            $file = Utils::path($this->sdopx->compileDir, $this->tplId . '.php');
            if (file_exists($file)) {
                Template::$complieCache[$this->tplId] = require($file);
            }
        }
        if (isset(Template::$complieCache[$this->tplId])) {
            $_property = &Template::$complieCache[$this->tplId];
            if (!$this->sdopx->compileCheck || $this->validProperties($_property)) {
                return $this->run($_property['runFunc']);
            } else {
                unset(Template::$complieCache[$this->tplId]);
            }
        }
        return $this->compileAndRunTemplate();
    }
1295339
public function compilePaginations()
	{
		foreach ($this->site->getPaginations() as $pagination) 
		{
			$template = $this->twig->loadTemplate( 'index.html.tpl' );
			$content = $template->render(array('site' => $this->site, 'pagination' => $pagination));
			$this->createFile($content, $pagination);
		}
	}
98909
public function render()
    {
        $source = $this->getOption('templateSource');
        $templatePathAndFilename = $this->getOption('templatePathAndFilename');
        if ($templatePathAndFilename !== null) {
            $source = file_get_contents($templatePathAndFilename);
        }

        return preg_replace_callback('/\{([a-zA-Z0-9\-_.]+)\}/', function ($matches) {
            return ObjectAccess::getPropertyPath($this->variables, $matches[1]);
        }, $source);
    }
558823
public function compileTemplateSource()
    {
        $source = $this->getSource();
        $this->addDependency($source);
        return $this->getCompiler()->compileTemplate();
    }
87195
def compiled(template, delimiters=DEFAULT_DELIMITERS):
    
    re_tag = delimiters_to_re(delimiters)

    # variable to save states
    tokens = []
    index = 0
    sections = []
    tokens_stack = []

    # root token
    root = Root('root')
    root.filters = copy.copy(filters)

    m = re_tag.search(template, index)
    while m is not None:
        token = None
        last_literal = None
        strip_space = False

        if m.start() > index:
            last_literal = Literal('str', template[index:m.start()], root=root)
            tokens.append(last_literal)

        # parse token
        prefix, name, suffix = m.groups()

        if prefix == '=' and suffix == '=':
            # {{=| |=}} to change delimiters
            delimiters = re.split(r'\s+', name)
            if len(delimiters) != 2:
                raise SyntaxError('Invalid new delimiter definition: ' + m.group())
            re_tag = delimiters_to_re(delimiters)
            strip_space = True

        elif prefix == '{' and suffix == '}':
            # {{{ variable }}}
            token = Variable(name, name, root=root)

        elif prefix == '' and suffix == '':
            # {{ name }}
            token = Variable(name, name, root=root)
            token.escape = True

        elif suffix != '' and suffix != None:
            raise SyntaxError('Invalid token: ' + m.group())

        elif prefix == '&':
            # {{& escaped variable }}
            token = Variable(name, name, root=root)

        elif prefix == '!':
            # {{! comment }}
            token = Comment(name, root=root)
            if len(sections) <= 0:
                # considered as standalone only outside sections
                strip_space = True

        elif prefix == '>':
            # {{> partial}}
            token = Partial(name, name, root=root)
            strip_space = True

            pos = is_standalone(template, m.start(), m.end())
            if pos:
                token.indent = len(template[pos[0]:m.start()])

        elif prefix == '#' or prefix == '^':
            # {{# section }} or # {{^ inverted }}

            # strip filter
            sec_name = name.split('|')[0].strip()
            token = Section(sec_name, name, root=root) if prefix == '#' else Inverted(name, name, root=root)
            token.delimiter = delimiters
            tokens.append(token)

            # save the tokens onto stack
            token = None
            tokens_stack.append(tokens)
            tokens = []

            sections.append((sec_name, prefix, m.end()))
            strip_space = True

        elif prefix == '/':
            tag_name, sec_type, text_end = sections.pop()
            if tag_name != name:
                raise SyntaxError("unclosed tag: '" + tag_name + "' Got:" + m.group())

            children = tokens
            tokens = tokens_stack.pop()

            tokens[-1].text = template[text_end:m.start()]
            tokens[-1].children = children
            strip_space = True

        else:
            raise SyntaxError('Unknown tag: ' + m.group())

        if token is not None:
            tokens.append(token)

        index = m.end()
        if strip_space:
            pos = is_standalone(template, m.start(), m.end())
            if pos:
                index = pos[1]
                if last_literal: last_literal.value = last_literal.value.rstrip(spaces_not_newline)

        m = re_tag.search(template, index)

    tokens.append(Literal('str', template[index:]))
    root.children = tokens
    return root
1287884
public function compileTemplateSource()
    {
        if (!$this->source->recompiled) {
            $this->properties['file_dependency'] = array();
            if ($this->source->components) {
                // for the extends resource the compiler will fill it
                // uses real resource for file dependency
                // $source = end($this->source->components);
                // $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $source->type);
            } else {
                $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
            }
        }
        // compile locking
        if ($this->smarty->compile_locking && !$this->source->recompiled) {
            if ($saved_timestamp = $this->compiled->timestamp) {
                touch($this->compiled->filepath);
            }
        }
        // call compiler
        try {
            $code = $this->compiler->compileTemplate($this);
        }
        catch (Exception $e) {
            // restore old timestamp in case of error
            if ($this->smarty->compile_locking && !$this->source->recompiled && $saved_timestamp) {
                touch($this->compiled->filepath, $saved_timestamp);
            }
            throw $e;
        }
        // compiling succeded
        if (!$this->source->recompiled && $this->compiler->write_compiled_code) {
            // write compiled template
            $_filepath = $this->compiled->filepath;
            if ($_filepath === false) {
                throw new SmartyException('getCompiledFilepath() did not return a destination to save the compiled template to');
            }
            Smarty_Internal_Write_File::writeFile($_filepath, $code, $this->smarty);
            $this->compiled->exists = true;
            $this->compiled->isCompiled = true;
        }
        // release compiler object to free memory
        unset($this->compiler);
    }
1077845
private function _compile() {
		
		// remove spaces
		$this->_result = str_replace('{{ ', '{{', $this->_content);
		$this->_result = str_replace(' }}', '}}', $this->_result);
		
		// check if
		if ($this->ifs) {
			foreach ($this->ifs as $key => $val) {
				$this->_setBool($key, $val);
			}
			empty($this->ifs);
		}
		
		// check loop
		if ($this->loops) {
			foreach ($this->loops as $key => $val) {
				$this->_setArray($key, $val);
			}
			empty($this->loops);
		}
		
		// check static replaces
		if ($this->vars) {
			foreach ($this->vars as $key => $val) {
				$this->_setString($key, $val);
			}
			empty($this->vars);
		}
		
		// include global vars
		if (is_array($this->injects)) {
			foreach ($this->injects as $inject) {
				global $ {
					$inject
				};
			}
			extract($this->injects);
		}
		
		// remove if and loop traces
		$this->_result = preg_replace("/<if\..*?>(.*?)<\/if\..*?>/s", '', $this->_result);
		$this->_result = preg_replace("/<loop\..*?>(.*?)<\/loop\..*?>/s", '', $this->_result);
		
		// check dynamic variables
		$pattern = "\{\{(.*?)\}\}";
		preg_match_all("/" . $pattern . "/", $this->_result, $matches, PREG_SET_ORDER);
		foreach ($matches as $block) {
			$chunk = $block[0];
			$codes = '<?php ' . $this->config['echo'] . '(' . trim($block[1]) . ')' . '; ?>';
			$this->_result = str_replace($chunk, $codes, $this->_result);
		}
		
		// attempt to create cache file for this template in storage directory
		$cache_file = md5($this->_filename) . '.compiled';
		$cache = $this->config['dir_cache'] . '/' . $cache_file;
		$fd = @fopen($cache, 'w+');
		@fwrite($fd, $this->_result);
		@fclose($fd);
		
		// when failed, try to create in /tmp
		if (!file_exists($cache)) {
			$cache = '/tmp/' . $cache_file;
			$fd = @fopen($cache, 'w+');
			@fwrite($fd, $this->_result);
			@fclose($fd);
		}
		
		// if template cache file created then include it, else use eval() to compile
		if (file_exists($cache)) {
			ob_start();
			include $cache;
			$this->_compiled = ob_get_contents();
			ob_end_clean();
			@unlink($cache);
		} else {
			ob_start();
			eval('?>' . $this->_result . '<?php ');
			$this->_compiled = ob_get_contents();
			ob_end_clean();
		}
	}
918452
protected function compile()
    {
        $categories = $this->getCategories();

        // Return if no categories are found
        if (null === $categories) {
            $this->Template->categories = '';

            return;
        }

        $param = System::getContainer()->get('codefog_news_categories.manager')->getParameterName();

        // Get the active category
        if (null !== ($activeCategory = NewsCategoryModel::findPublishedByIdOrAlias(Input::get($param)))) {
            $this->activeCategory = $activeCategory;

            // Add the canonical URL tag
            if ($this->news_enableCanonicalUrls) {
                $GLOBALS['TL_HEAD'][] = sprintf('<link rel="canonical" href="%s">', $GLOBALS['objPage']->getAbsoluteUrl());
            }
        }

        $ids = [];

        // Get the parent categories IDs
        /** @var NewsCategoryModel $category */
        foreach ($categories as $category) {
            $ids = \array_merge($ids, Database::getInstance()->getParentRecords($category->id, $category->getTable()));
        }

        $this->Template->categories = $this->renderNewsCategories((int) $this->news_categoriesRoot, \array_unique($ids));
    }
248804
public function compile()
	{
		// Add an image
		if ($this->addImage && trim($this->singleSRC)) {
			$fileModel = \FilesModel::findByUuid($this->singleSRC);
			if ($fileModel !== null && is_file(TL_ROOT . '/' . $fileModel->path)) {
				$this->singleSRC = $fileModel->path;
				$this->addImageToTemplate($this->Template, $this->arrData, null, null, $fileModel);
			}
		}

		$data = array();
		if ($this->rsce_data && substr($this->rsce_data, 0, 1) === '{') {
			$data = json_decode($this->rsce_data);
		}

		$data = $this->deserializeDataRecursive($data);

		foreach ($data as $key => $value) {
			$this->Template->$key = $value;
		}

		$self = $this;

		$this->Template->getImageObject = function() use($self) {
			return call_user_func_array(array($self, 'getImageObject'), func_get_args());
		};
		$this->Template->getColumnClassName = function() use($self) {
			return call_user_func_array(array($self, 'getColumnClassName'), func_get_args());
		};
	}
804821
protected function compile()
	{
		$data = deserialize($this->columnset, true);
		$articles = array();

		$container = \Netzmacht\ColumnSet\ColumnSet::prepareContainer($this->columnset_id);
		$i=0;

		foreach($data as $article) {
			$articles[] = array(
				'article' => $this->getArticle($article['article'], false, !((bool) $this->articleMarkup)),
				'class'   => $container[$i++][0],
				'id'      => $article['article'],
			);
		}

		$this->Template->articles = $articles;
	}
853710
private function getTemplates()
	{
		if (is_null($this->templates))
		{
			useLib('templates');
			$this->templates = new Templates();
		}

		return $this->templates;
	}
422261
public function compileTemplateSource(Smarty_Internal_Template $_template)
    {
        $_template->source->compileds = array();
        $this->file_dependency = array();
        $this->tpl_function = array();
        $this->includes = array();
        $this->nocache_hash = null;
        $this->unifunc = null;
        // compile locking
        if (!$_template->source->handler->recompiled) {
            if ($saved_timestamp = $_template->compiled->getTimeStamp()) {
                touch($_template->compiled->filepath);
            }
        }
        // call compiler
        try {
            $_template->loadCompiler();
            $code = $_template->compiler->compileTemplate($_template);
        }
        catch (Exception $e) {
            // restore old timestamp in case of error
            if (!$_template->source->handler->recompiled && $saved_timestamp) {
                touch($_template->compiled->filepath, $saved_timestamp);
            }
            throw $e;
        }
        // compiling succeeded
        if ($_template->compiler->write_compiled_code) {
            // write compiled template
            $this->write($_template, $code);
            $code = '';
        }
        // release compiler object to free memory
        unset($_template->compiler);
        return $code;
    }
789844
protected function _template() {
		$file = Libraries::locate('command.create.template', $this->template, [
			'filter' => false, 'type' => 'file', 'suffix' => '.txt.php'
		]);
		if (!$file || is_array($file)) {
			return false;
		}
		return file_get_contents($file);
	}
637800
protected function compile()
	{
		// generate modules
		$dataModules = deserialize($this->navbarModules, true);
		$modules = array();

		foreach ($dataModules as $module)
		{
			if($module['module'] != '')
			{
				$modules[] = $this->generateModule($module);
			}
		}

		if($this->cssID[1] == '')
		{
			$cssID = $this->cssID;
			$cssID[1] = 'navbar-default';
			$this->cssID = $cssID;
		}

		$this->Template->modules = $modules;
	}
1216729
private function compile()
    {
        $ff5c = "\x{ff5c}";
        if( PHP_VERSION_ID >= 70000){
            $ff5c = "\u{ff5c}";
        }
        $this->re = new Re($this->__opts__);

        // Define dynamic patterns
        $tlds = array_slice($this->__tlds__, 0);

        $this->onCompile();

        if (!$this->__tlds_replaced__) {
            $tlds[] = $this->tlds_2ch_src_re;
        }
        $tlds[] = $this->re->src_xn;

        $this->re->src_tlds = join('|', $tlds);

        $untpl = function(&$tpl){ return preg_replace('/%TLDS%/u', $this->re->src_tlds, $tpl); };

        $this->re->email_fuzzy      = '/' . $untpl($this->re->tpl_email_fuzzy) . '/ui';
        $this->re->link_fuzzy       = '/' . $untpl($this->re->tpl_link_fuzzy) . '/ui';
        $this->re->link_no_ip_fuzzy = '/' . $untpl($this->re->tpl_link_no_ip_fuzzy) . '/ui';
        $this->re->host_fuzzy_test  = '/' . $untpl($this->re->tpl_host_fuzzy_test) . '/ui';

        //
        // Compile each schema
        //

        $aliases = [];
        $this->__compiled__ = []; // Reset compiled data

        $schemaError = function (&$name, &$val) {
            throw new \Exception('(LinkifyIt) Invalid schema "' . $name . '": '. gettype ($val));
        };

        foreach($this->__schemas__ as $name => &$val) {
            if ($val === null) { continue; }

            $compiled = new \stdClass();
            $compiled->validate = null;
            $compiled->link = null;

            $this->__compiled__[$name] = $compiled;

            if (is_object($val)) {
                if( !isset($val->validate)){
                    $schemaError($name, $val);
                } else if (is_string($val->validate)) {
                    $compiled->validate = $this->createValidator($val->validate);
                } else if (is_callable($val->validate)) {
                    $compiled->validate = $val->validate;
                } else {
                    $schemaError($name, $val);
                }

                if (!isset($val->normalize)) {
                    $compiled->normalize = $this->createNormalizer();
                } else if (is_callable($val->normalize)) {
                    $compiled->normalize = $val->normalize;
                } else {
                    $schemaError($name, $val);
                }

                continue;
            }

            if (is_string($val)) {
                $aliases[] = $name;
                continue;
            }

            $schemaError($name, $val);
        }

        //
        // Compile postponed aliases
        //
        foreach($aliases as &$alias){
            if (isset($this->__schemas__[$alias]) && !isset($this->__compiled__[$this->__schemas__[$alias]])) {
                // Silently fail on missed schemas to avoid errons on disable.
                // $schemaError(alias, self.__schemas__[alias]);
                continue;
            }

            $this->__compiled__[$alias]->validate =
                $this->__compiled__[$this->__schemas__[$alias]]->validate;
            $this->__compiled__[$alias]->normalize =
                $this->__compiled__[$this->__schemas__[$alias]]->normalize;
        }

        //
        // Fake record for guessed links
        //
        $fake = new \stdClass();
        $fake->validate = null;
        $fake->normalize = $this->createNormalizer();
        $this->__compiled__[''] = $fake;

        /**
         * Merge objects
         * @param $str
         * @return mixed
         */
        $escapeRE = function($str) {
            return preg_replace("/([\.\?\*\+\^\$\[\]\\\(\)\{\}\|\-\/\^])/u", '\\\\${1}', $str);
        };

        //
        // Build schema condition
        //
        $slist = join('|',
            array_map($escapeRE,
                array_filter(
                    array_keys($this->__compiled__),
                    function ($name) {
                        // Filter disabled & fake schemas
                        return strlen ($name) > 0 && isset($this->__compiled__[$name]);
                    }
                )
            )
        );
//        var slist = Object.keys(self.__compiled__)
//            .filter(function (name) {
//                // Filter disabled & fake schemas
//                return name.length > 0 && self.__compiled__[name];
//            })
//            .map(escapeRE)
//            .join('|');

        // (?!_) cause 1.5x slowdown
        $this->re->schema_test   = "/(^|(?!_)(?:[><{$ff5c}]|" . $this->re->src_ZPCc . '))(' . $slist . ')/ui';
        $this->re->schema_search = "/(^|(?!_)(?:[><{$ff5c}]|" . $this->re->src_ZPCc . '))(' . $slist . ')/ui';


        $this->re->pretest       =
            '/((^|(?!_)(?:[><]|' . $this->re->src_ZPCc . '))(' . $slist . '))|' .
            '((^|(?!_)(?:[><]|' . $this->re->src_ZPCc . '))(' . $slist . '))|' .
            '@/ui';

        //
        // Cleanup
        //

        $this->resetScanCache();
    }