<?php
$nav_data = [
[
'id' => 1,
'href' => '/offers',
'title' => __('marketplace'),
'child' => [
[
'title' => __('all_offers'),
'href' => '/offers'
],
[
'title' => __('add_offer'),
'href' => ''
],
[
'title' => __('online_shop'),
'href' => ''
]
]
],
[
'id' => 2,
'href' => '',
'title' => __('news'),
],
[
'id' => 3,
'href' => '',
'title' => __('publications'),
'child' => [
[
'title' => __('all_publications'),
'href' => ''
],
[
'title' => __('agrocatalog'),
'href' => ''
],
[
'title' => __('add_publication'),
'href' => ''
]
]
],
[
'id' => 4,
'href' => '',
'title' => __('companies'),
'child' => [
[
'title' => __('catalog_of_companies'),
'href' => ''
],
[
'title' => __('add_company'),
'href' => ''
]
]
],
[
'id' => 5,
'title' => __('experts'),
'href' => ''
],
[
'id' => 6,
'title' => __('about'),
'href' => ''
]
];
function render_nav($data, $parent = false, $selected = 0)
{
foreach ($data as $item) {
if ($parent)
echo '<li><a href="' . $item['href'] . '">' . $item["title"] . '</a>';
else
echo '<li class="nav_item"><a class="nav_link' . ($selected == $item['id'] ? ' active' : '') . '" href="' . $item['href'] . '">' . $item["title"] . '</a>';
if (isset($item['child'])) {
echo '<ul class="nav_submenu">';
render_nav($item['child'], true, 0);
echo '</ul>';
}
echo '</li>';
}
}
<? foreach ($TREE as $row): ?>
<? if($row['li']=="open"): ?><ul><?endif?>
<? if($row['li']=="close"): ?></ul><?endif?>
<? if($row['id']!=0): ?>
<? if($id==$row['id']): ?>
<li><?=$row['title']?></li>
<? else: ?>
<li><a href="?id=<?=$row['id']?>"><?=$row['title']?></a></li>
<? endif ?>
<? endif ?>
<? endforeach ?>
</ul>
<ul>
<?php foreach ($nav_data as $item): ?>
<li>
<a href="<?php echo $item['href'] ?>">
<?php echo $item["title"] ?>
</a>
<?php if (!empty($item['child'])): ?>
<ul class="nav_submenu">
<?php foreach ($item['child'] as $child): ?>
<li class="nav_item">
<a class="nav_link<?php echo $selected == $item['id'] ? ' active' : '' ?>" href="<?php echo $child['href'] ?>">
<?php echo $child["title"] ?>
</a>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>
function render($template, $variables) {
extract($variables, EXTR_SKIP);
ob_start();
include $template;
return ob_get_clean();
}