/** * {includePart "file", name, params} * Alias for get_template_part() */ public function macroIncludePart(NMacroNode $node, NPhpWriter $writer) { $slug = $node->tokenizer->fetchWord(); $params = self::prepareIncludePartParams($writer->formatArray()); $slug = $writer->formatWord($slug); $name = $writer->formatWord($params['name']); return $writer->write('NCoreMacros::includeTemplate(' . __CLASS__ . '::getTemplatePart(' . $slug . ', ' . $name . '), ' . $params['params'] . ' + get_defined_vars(), $_l->templates[%var])->render()', $this->parser->templateId); }
/** * {control name[:method] [params]} */ public function macroControl(NMacroNode $node, NPhpWriter $writer) { $pair = $node->tokenizer->fetchWord(); if ($pair === FALSE) { throw new NCompileException("Missing control name in {control}"); } $pair = explode(':', $pair, 2); $name = $writer->formatWord($pair[0]); $method = isset($pair[1]) ? ucfirst($pair[1]) : ''; $method = NStrings::match($method, '#^\w*\z#') ? "render$method" : "{\"render$method\"}"; $param = $writer->formatArray(); if (!NStrings::contains($node->args, '=>')) { $param = substr($param, 6, -1); // removes array() } return ($name[0] === '$' ? "if (is_object($name)) \$_ctrl = $name; else " : '') . '$_ctrl = $_control->getComponent(' . $name . '); ' . 'if ($_ctrl instanceof IRenderable) $_ctrl->validateControl(); ' . "\$_ctrl->$method($param)"; }