将嵌套链接添加到 Pimcore 5 导航菜单
Adding Nested Links to a Pimcore 5 Navigation Menu
根据 Pimcore 5 文档,您可以使用以下例程手动将导航 link 添加到菜单:
$home = Document::getById(1);
$navigation->addPage([
'order' => -1, // put it in front of all the others
'uri' => '/', //path to homepage
'label' => $home->getProperty('navigation_name'), //visible label
'title' => $home->getProperty('navigation_title'), //tooltip text
'active' => $this->document->id == $home->id //active state
]);
但是,我无法辨别的是如何将 link 添加到导航菜单并定义父级 link,新添加的 link 应该嵌套在.
我在 Pimcore 5 github 回购中做了一些挖掘:
https://github.com/pimcore/pimcore/blob/master/pimcore/lib/Pimcore/Navigation/Page.php
我发现,当您使用上述规定的方法添加页面时,您可以在数组中包含一个 pages
条目,该数组嵌套了您要嵌套在其中的 links link.
例如:
<?php
// Manually add navigation links
// to a Pimcore\Navigation\Container object
$NavigationContainer->addPage(
// Add a top-level link at the front (order = -1)
array(
'order' => -1,
'uri' => '/test',
'label' => 'Test',
'title' => 'Test',
'pages' => array(
// Add a secondary-level link...
array(
'order' => 0,
'uri' => '/test/a',
'label' => 'Test A',
'title' => 'Test A',
'pages' => array(
// Add a tertiary-level link...
array(
'order' => 0,
'uri' => '/test/a/1',
'label' => 'Test A1',
'title' => 'Test A1'
),
// Add a tertiary-level link...
array(
'order' => 1,
'uri' => '/test/a/2',
'label' => 'Test A2',
'title' => 'Test A2'
)
)
),
// Add a secondary-level link...
array(
'order' => 0,
'uri' => '/test/b',
'label' => 'Test B',
'title' => 'Test B'
)
)
)
);
这会将以下内容添加到您的导航 HTML,假设您没有使用导航部分创建自定义呈现:
<li>
<a title="Test" href="/test">Test</a>
<ul>
<li>
<a title="Test A" href="/test/a">Test A</a>
<ul>
<li><a title="Test A1" href="/test/a/1">Test A1</a></li>
<li><a title="Test A2" href="/test/a/2">Test A1</a></li>
</ul>
</li>
<li><a title="Test B" href="/test/b">Test B</a></li>
</ul>
</li>
根据 Pimcore 5 文档,您可以使用以下例程手动将导航 link 添加到菜单:
$home = Document::getById(1);
$navigation->addPage([
'order' => -1, // put it in front of all the others
'uri' => '/', //path to homepage
'label' => $home->getProperty('navigation_name'), //visible label
'title' => $home->getProperty('navigation_title'), //tooltip text
'active' => $this->document->id == $home->id //active state
]);
但是,我无法辨别的是如何将 link 添加到导航菜单并定义父级 link,新添加的 link 应该嵌套在.
我在 Pimcore 5 github 回购中做了一些挖掘:
https://github.com/pimcore/pimcore/blob/master/pimcore/lib/Pimcore/Navigation/Page.php
我发现,当您使用上述规定的方法添加页面时,您可以在数组中包含一个 pages
条目,该数组嵌套了您要嵌套在其中的 links link.
例如:
<?php
// Manually add navigation links
// to a Pimcore\Navigation\Container object
$NavigationContainer->addPage(
// Add a top-level link at the front (order = -1)
array(
'order' => -1,
'uri' => '/test',
'label' => 'Test',
'title' => 'Test',
'pages' => array(
// Add a secondary-level link...
array(
'order' => 0,
'uri' => '/test/a',
'label' => 'Test A',
'title' => 'Test A',
'pages' => array(
// Add a tertiary-level link...
array(
'order' => 0,
'uri' => '/test/a/1',
'label' => 'Test A1',
'title' => 'Test A1'
),
// Add a tertiary-level link...
array(
'order' => 1,
'uri' => '/test/a/2',
'label' => 'Test A2',
'title' => 'Test A2'
)
)
),
// Add a secondary-level link...
array(
'order' => 0,
'uri' => '/test/b',
'label' => 'Test B',
'title' => 'Test B'
)
)
)
);
这会将以下内容添加到您的导航 HTML,假设您没有使用导航部分创建自定义呈现:
<li>
<a title="Test" href="/test">Test</a>
<ul>
<li>
<a title="Test A" href="/test/a">Test A</a>
<ul>
<li><a title="Test A1" href="/test/a/1">Test A1</a></li>
<li><a title="Test A2" href="/test/a/2">Test A1</a></li>
</ul>
</li>
<li><a title="Test B" href="/test/b">Test B</a></li>
</ul>
</li>