public static function compile(Compiler $compiler, $file)
    {
        $file = substr($file, 1, -1);
        if ($file === '') {
            return null;
        }
        if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
            // resource:identifier given, extract them
            $resource = $m[1];
            $identifier = $m[2];
        } else {
            // get the current template's resource
            $resource = $compiler->getCore()->getTemplate()->getResourceName();
            $identifier = $file;
        }
        $identifier = str_replace('\\\\', '\\', $identifier);
        $tpl = $compiler->getCore()->templateFactory($resource, $identifier);
        if ($tpl === null) {
            throw new CompilationException($compiler, 'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
        } else {
            if ($tpl === false) {
                throw new CompilationException($compiler, 'Load Templates : Resource "' . $resource . '" does not support includes.');
            }
        }
        $cmp = clone $compiler;
        $cmp->compile($compiler->getCore(), $tpl);
        foreach ($cmp->getTemplatePlugins() as $template => $args) {
            $compiler->addTemplatePlugin($template, $args['params'], $args['uuid'], $args['body']);
        }
        foreach ($cmp->getUsedPlugins() as $plugin => $type) {
            $compiler->addUsedPlugin($plugin, $type);
        }
        $out = '// checking for modification in ' . $resource . ':' . $identifier . "\r\n";
        $modCheck = $tpl->getIsModifiedCode();
        if ($modCheck) {
            $out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
        } else {
            $out .= 'try {
	$tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '");
} catch (\\Dwoo\\Exception $e) {
	$this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING);
}
if ($tpl === null)
	$this->triggerError(\'Load Templates : Resource "' . $resource . ':' . $identifier . '" was not found.\', E_USER_WARNING);
elseif ($tpl === false)
	$this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING);
if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }';
        }
        return $out;
    }
 public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $paramstr = '\\Dwoo\\Core $core';
     $init = 'static $_callCnt = 0;' . "\n" . '$core->scope[\' ' . $params['uuid'] . '\'.$_callCnt] = array();' . "\n" . '$_scope = $core->setScope(array(\' ' . $params['uuid'] . '\'.($_callCnt++)));' . "\n";
     $cleanup = '/* -- template end output */ $core->setScope($_scope, true);';
     foreach ($params['*'] as $param => $defValue) {
         if ($defValue === null) {
             $paramstr .= ', $' . $param;
         } else {
             $paramstr .= ', $' . $param . ' = ' . $defValue;
         }
         $init .= '$core->scope[\'' . $param . '\'] = $' . $param . ";\n";
     }
     $init .= '/* -- template start output */';
     $funcName = $params['name'] . $params['uuid'];
     $search = array('$this->charset', '$this->', '$this,');
     $replacement = array('$core->getCharset()', '$core->', '$core,');
     $content = str_replace($search, $replacement, $content);
     $body = '$' . $funcName . ' = function(' . $paramstr . ') use(&$' . $funcName . ') {' . "\n{$init}" . Compiler::PHP_CLOSE . $prepend . $content . $append . Compiler::PHP_OPEN . $cleanup . "\n};";
     $compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body);
 }