diff --git a/src/Tags/Structure.php b/src/Tags/Structure.php index 3bf57d1082..a3a132dc9f 100644 --- a/src/Tags/Structure.php +++ b/src/Tags/Structure.php @@ -64,7 +64,13 @@ protected function structure($handle) 'max_depth' => $this->params->get('max_depth'), ]); - return $this->toArray($tree); + $value = $this->toArray($tree); + + if ($this->parser && ($as = $this->params->get('as'))) { + return [$as => $value]; + } + + return $value; } protected function ensureStructureExists(string $handle): void diff --git a/tests/Tags/StructureTagTest.php b/tests/Tags/StructureTagTest.php index 1694339757..03baf77b66 100644 --- a/tests/Tags/StructureTagTest.php +++ b/tests/Tags/StructureTagTest.php @@ -220,6 +220,48 @@ public function it_renders_a_nav_with_scope() ])); } + #[Test] + public function it_renders_a_nav_with_as() + { + $this->createCollectionAndNav(); + + // The html uses tags (could be any tag, but i is short) to prevent whitespace comparison issues in the assertion. + $template = <<<'EOT' + +EOT; + + $expected = <<<'EOT' + +EOT; + + $this->assertXmlStringEqualsXmlString($expected, (string) Antlers::parse($template, [ + 'foo' => 'bar', // to test that cascade is inherited. + ])); + } + #[Test] public function it_hides_unpublished_entries_by_default() {