public function before(PHPTAL_Php_CodeWriter $codewriter) { $macroname = strtr(trim($this->expression), '-', '_'); if (!preg_match('/^[a-z0-9_]+$/i', $macroname)) { throw new PHPTAL_ParserException('Bad macro name "' . $macroname . '"', $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); } if ($codewriter->functionExists($macroname)) { throw new PHPTAL_TemplateException("Macro {$macroname} is defined twice", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); } $codewriter->doFunction($macroname, 'PHPTAL $_thistpl, PHPTAL $tpl'); $codewriter->doSetVar('$tpl', 'clone $tpl'); $codewriter->doSetVar('$ctx', '$tpl->getContext()'); $codewriter->doInitTranslator(); $codewriter->doXmlDeclaration(true); $codewriter->doDoctype(true); }