diff --git a/src/Latte/Essential/Nodes/ImportNode.php b/src/Latte/Essential/Nodes/ImportNode.php index cc2331b3f..923656222 100644 --- a/src/Latte/Essential/Nodes/ImportNode.php +++ b/src/Latte/Essential/Nodes/ImportNode.php @@ -9,6 +9,7 @@ namespace Latte\Essential\Nodes; +use Latte\Compiler\Nodes\Php\Expression\ArrayNode; use Latte\Compiler\Nodes\Php\ExpressionNode; use Latte\Compiler\Nodes\StatementNode; use Latte\Compiler\PrintContext; @@ -16,11 +17,12 @@ /** - * {import "file"} + * {import "file"[, args]} */ class ImportNode extends StatementNode { public ExpressionNode $file; + public ArrayNode $args; public static function create(Tag $tag): static @@ -28,6 +30,8 @@ public static function create(Tag $tag): static $tag->expectArguments(); $node = new static; $node->file = $tag->parser->parseUnquotedStringOrExpression(); + $tag->parser->stream->tryConsume(','); + $node->args = $tag->parser->parseArguments(); return $node; } @@ -35,8 +39,9 @@ public static function create(Tag $tag): static public function print(PrintContext $context): string { return $context->format( - '$this->createTemplate(%node, $this->params, "import")->render() %line;', + '$this->createTemplate(%node, %node? + $this->params, "import")->render() %line;', $this->file, + $this->args, $this->position, ); } @@ -45,5 +50,6 @@ public function print(PrintContext $context): string public function &getIterator(): \Generator { yield $this->file; + yield $this->args; } } diff --git a/tests/tags/import.args.phpt b/tests/tags/import.args.phpt new file mode 100644 index 000000000..930312e96 --- /dev/null +++ b/tests/tags/import.args.phpt @@ -0,0 +1,35 @@ +setLoader(new Latte\Loaders\StringLoader([ + 'main' => <<<'XX' + + {import "inc", val: 123} + {include test} + + XX, + 'inc' => <<<'XX' + + outer text + {define test} + Test {$val} + {/define} + + XX, +])); + +Assert::match( + 'Test 123', + trim($latte->renderToString('main')), +); diff --git a/tests/tags/import.nodes.phpt b/tests/tags/import.nodes.phpt index e8566c1d9..f0250ac0d 100644 --- a/tests/tags/import.nodes.phpt +++ b/tests/tags/import.nodes.phpt @@ -17,5 +17,22 @@ Assert::match(<<<'XX' Import: Variable: name: var + Array: Fragment: XX, exportTraversing('{import $var}')); + + +Assert::match(<<<'XX' + Template: + Fragment: + Import: + Variable: + name: var + Array: + ArrayItem: + Identifier: + name: param + String: + value: val + Fragment: + XX, exportTraversing('{import $var, param: val}'));