SmartTemplateParser Constructor

@param string $template_filename HTML Template Filename
182278
function SmartTemplateParser ( $template_filename )
		{
			// Load Template
			if ($hd = @fopen($template_filename, "r"))
			{
				if (filesize($template_filename))
				{
					$this->template = fread($hd, filesize($template_filename));
				}
				else
				{
					$this->template = "SmartTemplate Parser Error: File size is zero byte: '$template_filename'";
				}
				fclose($hd);
				// Extract the name of the template directory
				$this->template_dir = dirname($template_filename);
			}
			else
			{
				$this->template = "SmartTemplate Parser Error: File not found: '$template_filename'";
			}
		}
385988
public function setTemplatePathAndFilename($templatePathAndFilename)
    {
        $this->baseRenderingContext->getTemplatePaths()->setTemplatePathAndFilename($templatePathAndFilename);

        $partialRootPaths = $this->baseRenderingContext->getTemplatePaths()->getPartialRootPaths();
        $layoutRootPaths = $this->baseRenderingContext->getTemplatePaths()->getLayoutRootPaths();
        array_unshift($partialRootPaths, Files::concatenatePaths([dirname($templatePathAndFilename), 'Partials']));
        array_unshift($layoutRootPaths, Files::concatenatePaths([dirname($templatePathAndFilename), 'Layouts']));
        $this->baseRenderingContext->getTemplatePaths()->setPartialRootPaths($partialRootPaths);
        $this->baseRenderingContext->getTemplatePaths()->setLayoutRootPaths($layoutRootPaths);
    }
357260
public function setTemplate()
    {
        // Creates the loader & sets the template directory path
        $loader = new FilesystemLoader('../src/View');

        // Creates the template engine
        $twig = new Environment($loader, array(
            'cache' => false,
            'debug' => true
        ));

        // Adds Twig extensions
        $twig->addExtension(new DebugExtension());
        $twig->addExtension(new PamTwigExtension());

        // Attributes the template engine to the current object
        $this->twig = $twig;
    }
1098523
public function onLoadTemplate(ITemplateFactory $templateFactory, $templateFile, $presenterName)
	{
		if (!$this->activeTheme) {
			return;
		}
		$templateFactory->addTemplate(
			$this->formatTemplateFilePath($this->activeTheme, $templateFile, $presenterName)
		);
		$templateFactory->addTemplate(
			$this->formatTemplateFilePath($this->activeTheme, $templateFile)
		);

		$parent = $this->activeTheme->getParent();
		if (!$parent) {
			return;
		}
		$parentTheme = $this->getTheme($parent);
		$templateFactory->addTemplate(
			$this->formatTemplateFilePath($parentTheme, $templateFile, $presenterName)
		);
		$templateFactory->addTemplate(
			$this->formatTemplateFilePath($parentTheme, $templateFile)
		);
	}
271679
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
    {
        $uid = '';
        $sources = array();
        $components = explode('|', $source->name);
        $exists = true;
        foreach ($components as $component) {
            /* @var \Smarty_Template_Source $_s */
            $_s = Smarty_Template_Source::load(null, $source->smarty, $component);
            if ($_s->type == 'php') {
                throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
            }
            $sources[ $_s->uid ] = $_s;
            $uid .= $_s->filepath;
            if ($_template) {
                $exists = $exists && $_s->exists;
            }
        }
        $source->components = $sources;
        $source->filepath = $_s->filepath;
        $source->uid = sha1($uid);
        $source->exists = $exists;
        if ($_template) {
            $source->timestamp = $_s->timestamp;
        }
    }
1349843
protected function compileTemplate($fileName)
    {
        try {
            $this->
                twigView->
                getTwig()->
                loadTemplate($fileName);
            $this->out('<success>' . $fileName . '</success>');
        } catch (\Exception $exception) {
            $this->out('<error>' . $fileName . '</error>');
            $this->out('<error>' . $exception->getMessage() . '</error>');
        }
    }
826467
static function compileParentBlock($compiler, $_name = null)
    {
        // if called by {$smarty.block.parent} we must search the name of enclosing {block}
        if ($_name == null) {
            $stack_count = count($compiler->_tag_stack);
            while (--$stack_count >= 0) {
                if ($compiler->_tag_stack[$stack_count][0] == 'block') {
                    $_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "\"'");
                    break;
                }
            }
        }
        if ($_name == null) {
            $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->lex->taglineno);
        }
        if (empty(Smarty_Internal_Compile_Block::$nested_block_names)) {
            $compiler->trigger_template_error(' illegal {$smarty.block.parent} in parent template ', $compiler->lex->taglineno);
        }
        Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= Smarty_Internal_Compile_Block::parent;
        $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
        $compiler->has_code = false;
        return;
    }
1039405
def parse_from_template(template_name):
    
    thisdir = os.path.split(__file__)[0]
    filename = os.path.join(
        thisdir, '..', 'templates', '%s.xml' % template_name
    )
    with open(filename, 'rb') as f:
        xml = f.read()
    return parse_xml(xml)
1230591
public function parse( $template_file )
    {
        if ( file_exists( $template_file ) ) {
            $content = file_get_contents($template_file);

            foreach ( $this->vars as $key => $value ) {
                if ( is_array( $value ) ) {
                    $content = $this->parsePair($key, $value, $content);
                } else {
                    $content = $this->parseSingle($key, (string) $value, $content);
                }
            }

            return $content;
        } else {
            exit( '<h1>Template error</h1>' );
        }
    }
1290345
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
    {
        $file = $source->name;
        // absolute file ?
        if ($file[0] == '/' || $file[1] == ':') {
            $file = $source->smarty->_realpath($file, true);
            return is_file($file) ? $file : false;
        }
        // go relative to a given template?
        if ($file[0] == '.' && $_template && isset($_template->parent) && $_template->parent->_objType == 2 &&
            preg_match('#^[.]{1,2}[\\\/]#', $file)
        ) {
            if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' &&
                !isset($_template->parent->_cache['allow_relative_path'])
            ) {
                throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
            }
            $path = dirname($_template->parent->source->filepath) . DS . $file;
            // normalize path
            $path = $source->smarty->_realpath($path);
            // files relative to a template only get one shot
            return is_file($path) ? $path : false;
        }
        // normalize DS
        if (strpos($file, DS == '/' ? '\\' : '/') !== false) {
            $file = str_replace(DS == '/' ? '\\' : '/', DS, $file);
        }

        $_directories = $source->smarty->getTemplateDir(null, $source->isConfig);
        // template_dir index?
        if ($file[0] == '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) {
            $file = $fileMatch[2];
            $_indices = explode(',', $fileMatch[1]);
            $_index_dirs = array();
            foreach ($_indices as $index) {
                $index = trim($index);
                // try string indexes
                if (isset($_directories[$index])) {
                    $_index_dirs[] = $_directories[$index];
                } elseif (is_numeric($index)) {
                    // try numeric index
                    $index = (int) $index;
                    if (isset($_directories[$index])) {
                        $_index_dirs[] = $_directories[$index];
                    } else {
                        // try at location index
                        $keys = array_keys($_directories);
                        if (isset($_directories[$keys[$index]])) {
                            $_index_dirs[] = $_directories[$keys[$index]];
                        }
                    }
                }
            }
            if (empty($_index_dirs)) {
                // index not found
                return false;
            } else {
                $_directories = $_index_dirs;
            }
        }

        // relative file name?
        foreach ($_directories as $_directory) {
            $path = $_directory . $file;
            if (is_file($path)) {
                return (strpos($path, '.' . DS) !== false) ? $source->smarty->_realpath($path) : $path;
            }
        }
        if (!isset($_index_dirs)) {
            // Could be relative to cwd
            $path = $source->smarty->_realpath($file, true);
            if (is_file($path)) {
                return $path;
            }
        }
        // Use include path ?
        if ($source->smarty->use_include_path) {
            return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty);
        }
        return false;
    }
147061
public function parse_template()
    {
        $self = $this;
        return preg_replace_callback('/\{\{([a-zA-Z\d-_]+)\}\}/', function($a) use($self) {
            $component = $self->get_component($a[1]);
            return $component->render();
        }, $this->model['template']);
    }
773178
public function start_compile(Smarty_Internal_Template $template)
    {
        static $_is_stringy = array('string' => true, 'eval' => true);
        if (!empty($template->compiler->trace_uid)) {
            $key = $template->compiler->trace_uid;
            if (!isset($this->template_data[$this->index][$key])) {
                if (isset($_is_stringy[$template->source->type])) {
                    $this->template_data[$this->index][$key]['name'] =
                        '\'' . substr($template->source->name, 0, 25) . '...\'';
                } else {
                    $this->template_data[$this->index][$key]['name'] = $template->source->filepath;
                }
                $this->template_data[$this->index][$key]['compile_time'] = 0;
                $this->template_data[$this->index][$key]['render_time'] = 0;
                $this->template_data[$this->index][$key]['cache_time'] = 0;
            }
        } else {
            if (isset($this->ignore_uid[$template->source->uid])) {
                return;
            }
            $key = $this->get_key($template);
        }
        $this->template_data[$this->index][$key]['start_time'] = microtime(true);
    }
1195278
function it_tokenize_templates()
    {
        $this->tokenize(new Cursor("TEXT <{ ... . keyword 'string' \"string\" 3.14 var null true false }> TEXT"))->shouldBeLike([
            new Token(Token::TYPE_TEXT, 'TEXT ', 1),
            new Token(Token::TYPE_OPEN_TAG | Token::TYPE_SYMBOL, '<{', 1),
            new Token(Token::TYPE_SYMBOL, '...', 1),
            new Token(Token::TYPE_SYMBOL, '.', 1),
            new Token(Token::TYPE_KEYWORD | Token::TYPE_IDENTIFIER, 'keyword', 1),
            new Token(Token::TYPE_STRING | Token::TYPE_SINGLE_QUOTED, 'string', 1),
            new Token(Token::TYPE_STRING | Token::TYPE_DOUBLE_QUOTED, 'string', 1),
            new Token(Token::TYPE_NUMBER, '3.14', 1),
            new Token(Token::TYPE_IDENTIFIER, 'var', 1),
            new Token(Token::TYPE_CONSTANT, 'null', 1),
            new Token(Token::TYPE_CONSTANT, 'true', 1),
            new Token(Token::TYPE_CONSTANT, 'false', 1),
            new Token(Token::TYPE_CLOSE_TAG | Token::TYPE_SYMBOL, '}>', 1),
            new Token(Token::TYPE_TEXT, ' TEXT', 1),
            new Token(Token::TYPE_EOF, null, 1),
        ]);
    }
25146
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
    {
        $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
        $_filepath = $compiled->source->uid;
        // if use_sub_dirs, break file into directories
        if ($_template->smarty->use_sub_dirs) {
            $_filepath = substr($_filepath, 0, 2) . DS
             . substr($_filepath, 2, 2) . DS
             . substr($_filepath, 4, 2) . DS
             . $_filepath;
        }
        $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
        if (isset($_compile_id)) {
            $_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
        }
        // caching token
        if ($_template->caching) {
            $_cache = '.cache';
        } else {
            $_cache = '';
        }
        $_compile_dir = $_template->smarty->getCompileDir();
        // set basename if not specified
        $_basename = $this->getBasename($compiled->source);
        if ($_basename === null) {
            $_basename = basename( preg_replace('![^\w\/]+!', '_', $compiled->source->name) );
        }
        // separate (optional) basename by dot
        if ($_basename) {
            $_basename = '.' . $_basename;
        }

        $compiled->filepath = $_compile_dir . $_filepath . '.' . $compiled->source->type . $_basename . $_cache . '.php';
    }
1346688
private function loadCompiledTemplate(Smarty_Internal_Template $_template)
    {
        if (function_exists('opcache_invalidate')) {
            opcache_invalidate($_template->compiled->filepath);
        }
        $_smarty_tpl = $_template;
        if (defined('HHVM_VERSION')) {
            $_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->compiled->filepath);
        } else {
            include($_template->compiled->filepath);
        }
    }
64627
function compile() {
		
		// if no setContent() then load the from file
		if (!$this->getContent()) {
			
			// if no setTemplate() then use default template file
			if (!$this->getTemplate()) {
				$this->setTemplate($this->config['dir_template'] . '/' . $this->name . $this->config['extension']);
			}
			
			$this->_setContentFromFile();
		}
		
		$this->_compile();
		
		return $this;
	}
1130357
protected function _parseExtend() {
        foreach (Template::$_extends as $extend) {
            $this->_content = $extend['class']::$extend['method']($this->_content);
        }

        foreach (Config::instance()->config['user']['template'] as $extend) {
            $this->_content = $extend['class']::$extend['method']($this->_content);
        }
    }