Multi-lingual page structure was implemented according this tutorial: Building Sites in Multiple Languages
Here's my snippet of the main navigation:
<nav class="nav-lng">
<a href="<?php echo View::url('/'); ?>" class="btn lng-fi spr"></a>
<a href="<?php echo View::url('/en/home'); ?>" class="btn lng-en spr"></a>
</nav>
<nav class="nav-main">
<?php
$nav = BlockType::getByHandle('autonav');
if ($c->getCollectionAttributeValue('in_english'))
{
$nav->controller->displayPages = 'custom';
$nav->controller->displayPagesCID = '123'; // additional lng stackparent's ID here!
}
else
{
$nav->controller->displayPages = 'top';
}
$nav->controller->orderBy = 'display_asc';
$nav->controller->displaySubPages = 'none';
$nav->render('templates/select_path'); // my custom template's name
?>
</nav>
For hierarchically aware "current page trail" autonav I used a modified template, as community member 'ecomatt' had posted in his discussion Highlight Auto Nav current page and parent pages.
Here is the snippet, save it under /blocks/autonav/templates. I used the file name 'select_path'.
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$aBlocks = $controller->generateNav();
$c = Page::getCurrentPage();
$containsPages = false;
$nh = Loader::helper('navigation');
//this will create an array of parent cIDs
$inspectC=$c;
$selectedPathCIDs=array( $inspectC->getCollectionID() );
$parentCIDnotZero=true;
while($parentCIDnotZero){
$cParentID=$inspectC->cParentID;
if(!intval($cParentID)){
$parentCIDnotZero=false;
}else{
$selectedPathCIDs[]=$cParentID;
$inspectC=Page::getById($cParentID);
}
}
foreach($aBlocks as $ni) {
$_c = $ni->getCollectionObject();
if (!$_c->getCollectionAttributeValue('exclude_nav')) {
if (!$containsPages) {
// this is the first time we've entered the loop so we print out the UL tag
echo("<ul class=\"nav\">");
}
$containsPages = true;
$thisLevel = $ni->getLevel();
if ($thisLevel > $lastLevel) {
echo("<ul>");
} else if ($thisLevel < $lastLevel) {
for ($j = $thisLevel; $j < $lastLevel; $j++) {
if ($lastLevel - $j > 1) {
echo("</li></ul>");
} else {
echo("</li></ul></li>");
}
}
} else if ($i > 0) {
echo("</li>");
}
$pageLink = false;
if ($_c->getCollectionAttributeValue('replace_link_with_first_in_nav')) {
$subPage = $_c->getFirstChild();
if ($subPage instanceof Page) {
$pageLink = $nh->getLinkToCollection($subPage);
}
}
if (!$pageLink) {
$pageLink = $ni->getURL();
}
// MODIFIED! this is the new function that allows nav-selected as well as nav-path-selected
if ($ni->isActive($c) || ($c->getCollectionID() == $_c->getCollectionID()))
{
echo('<li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected" href="' . $pageLink . '">' . $ni->getName() . '</a>');
}
elseif ( in_array($_c->getCollectionID(),$selectedPathCIDs) && $_c->getCollectionID() != 1 )
{
echo('<li class="nav-path-selected"><a class="nav-path-selected" href="' . $pageLink . '">' . $ni->getName() . '</a>');
}
else
{
echo('<li><a href="' . $pageLink . '">' . $ni->getName() . '</a>');
}
$lastLevel = $thisLevel;
$i++;
}
}
$thisLevel = 0;
if ($containsPages) {
for ($i = $thisLevel; $i <= $lastLevel; $i++) {
echo("</li></ul>");
}
}
?>
Now you can hook with CSS on the class '.nav-path-selected' on both the 'li' and 'a' elements.
And finally my page template 'left_sidebar.php' in my custom theme's folder:
<?php defined('C5_EXECUTE') or die(_("Access Denied."));
$this->inc('elements/header.php');
?>
<nav class="nav-sub">
<?php
$nh = Loader::helper('navigation');
$trail = $nh->getTrailToCollection($c);
//count how many levels down the hierarchy is the current page
$levels = count($trail);
$curID = $c->getCollectionID();
$parentID = $c->getCollectionParentID();
// translated pages have a checkbox attribute set
// if translated page, these reside in the own stack adding one more level to hierarchy
$mod = ($c->getCollectionAttributeValue('in_english')) ? 1 : 0;
// in this code there is only mainpage and subpage levels visible in their own navigations
// you could add the grandParent by getting and saving it's ID on the var $grandParentID,
// unquoting the two quotes below and changing the 'displaySubPageLevelsNum'
$is1stLevel = 1 + $mod;
$is2ndLevel = 2 + $mod;
// $is3rdLevel = 3 + $mod;
if ($levels == $is1stLevel) { $disp = $curID; }
else if ($levels == $is2ndLevel) { $disp = $parentID; }
// else if ($levels == $is3rdLevel) { $disp = $grandParentID; }
$sn = BlockType::getByHandle('autonav');
$sn->controller->displayPages = 'custom';
$sn->controller->displayPagesCID = $disp;
$sn->controller->displaySubPageLevelsNum = '0'; //change here if needed
$sn->controller->orderBy = 'display_asc';
$sn->render('templates/header_menu');
?>
</nav>
<section id="content" role="main">
<?php
$b = new Area('Main');
$b->display($c);
?>
</section>
<?php $this->inc('elements/footer.php'); ?>
Loading Conversation