/** * @see \Ableron\Core\Template\Plugins\Interfaces\CompilerPluginInterface::compileOpeningTag() */ public function compileOpeningTag(TemplateCompiler $templateCompiler) { // check whether last opened tag is an if-tag if ($templateCompiler->getLastCompilerPluginTagParameter('tagName') !== 'if') { throw new SystemException(sprintf('Unexpected {elseif} in template "%s" on line %s', $templateCompiler->getCurrentTemplateName(), $templateCompiler->getCurrentLineNumber()), 0, E_USER_ERROR, __FILE__, __LINE__); } // compile the tag return sprintf('<?php } elseif (%s) { ?>', $this->getTag()->getArgumentString()); }
/** * @see \Ableron\Core\Template\Plugins\Interfaces\CompilerPluginInterface::compileOpeningTag() */ public function compileOpeningTag(TemplateCompiler $templateCompiler) { // get parent foreach-tag $foreachTag = $templateCompiler->getLastCompilerPluginTagParameter('compilerPlugin')->getTag(); // check whether last opened tag is a foreach-tag if ($foreachTag->getTagName() !== 'foreach') { throw new SystemException(sprintf('Unexpected {foreachelse} in template "%s" on line %s', $templateCompiler->getCurrentTemplateName(), $templateCompiler->getCurrentLineNumber()), 0, E_USER_ERROR, __FILE__, __LINE__); } // extract items from foreach-tag argument string $items = preg_replace('#\\s*(.+?)\\s+as\\s+.*$#', '$1', $foreachTag->getArgumentString()); // close foreach-tag and use if-statement to check for empty foreach-input return sprintf('<?php } ?>%s<?php if (empty(%s)) { ?>', StringUtil::CHAR_LINE_FEED, $items); }
/** * Extracts the path of the parent template file of the given template. * * Returns NULL in case the given template does not has a parent template. * * @param string $template The template to extract the parent template path from * @return string|null */ private function extractParentTemplatePath($template) { // extract template tags from given template $templateTags = $this->templateCompiler->extractTemplateTags($template); // check whether at least one tag has been found if (isset($templateTags[0])) { // get first tag $firstTemplateTag = new TemplateTag($templateTags[0]); // return parent template path in case first tag is an extends-tag if ($firstTemplateTag->getTagName() === 'extends') { return $firstTemplateTag->getArgument(0); } } // given template does not has a parent template return null; }
/** * @see \Ableron\Core\Template\Plugins\Interfaces\CompilerPluginInterface::compileClosingTag() */ public function compileClosingTag(TemplateCompiler $templateCompiler) { throw new SystemException(sprintf('Unknown tag {/%s} in template "%s" on line %s', $this->getTag()->getTagName(), $templateCompiler->getCurrentTemplateName(), $templateCompiler->getCurrentLineNumber()), 0, E_USER_ERROR, __FILE__, __LINE__); }