Jump to content

inserting Language Dropdown into main menu


Recommended Posts

1 trying to add extra pages to default _uikit.php function ukNavBarNav-> fails ...it requires 1 array

2 trying to add dropdown  multilingual menu there-> fails it requires pages array and problem n1

3 adding standard php multilingual code (for menu generation) to UkNavBarNav ->fails as variable $languages is empty there


SO What is the best way to navigate(menu) in Blog profile and how to add language switcher in a drop down manner?

Link to comment
Share on other sites

Look . All you describe here has nothing to do with my question. 

I added multilingual support to blog scheme and it works perfectly showing multilingual menu. But as I asked I need to integrate it into main menu using build in functionality. And I believe there is a really easy way for that. 

Secondly why should I use menu builder if I can simply fix a template with pure php. All I need is to pass $languages to function uknavbarnav somehow or decide a function in parts. No idea yet. Buy surely there must be a simple answer

  • Like 1
Link to comment
Share on other sites

you saved my day, work perfectly, now i have language choice dropdown in main menu,


function ukNavbarNav(PageArray $items, $options = array()) {
	if(!$items->count) return '';
	$defaults = array(
		'dropdown' => null, // array of page paths, page IDs, or template names where dropdown is allowed (null=allow all)

	$options = _ukMergeOptions($defaults, $options);
	$page = $items->wire('page');
	$activeItems = $page->parents("id>1")->and($page);
	$out = "<ul class='uk-navbar-nav'>";
	$liActive = "<li class='uk-active'>";
	$li = "<li>";
	foreach($items as $item) {

		$out .= $activeItems->has($item) ? $liActive : $li;
		$out .= "<a href='$item->url'>$item->title</a>";
		// determine whether dropdown should be used for this $item
		$useDropdown = false;
		if($options['dropdown'] === null) {
			$useDropdown = $item->hasChildren && $item->id > 1;
		} else if($item->hasChildren && is_array($options['dropdown'])) {
			foreach($options['dropdown'] as $s) {
				if($item->template->name === $s || $page->path === $s || $page->id === $s) {
					$useDropdown = true;

		if($useDropdown) {
			$out .= "<div class='uk-navbar-dropdown'>";
			$out .= "<ul class='uk-nav uk-navbar-dropdown-nav'>";
			foreach($item->children as $child) {
				$out .= $activeItems->has($child) ? $liActive : $li;
				$out .= "<a href='$child->url'>$child->title</a></li>";
			$out .= "</ul></div>";
		$out .= "</li>";
    $out.= '<li>
    <a hreflang="en" href="/" class="" aria-expanded="false">Language</a>
    <div class="mod-languages uk-navbar-dropdown ">
	<!-- dropdown gruprv -->
<ul class="languages uk-nav uk-navbar-dropdown-nav" aria-hidden="true" >';

		foreach(wire('languages') as $language) {
			if(!$page->viewable($language)) continue; // is page viewable in this language?
			if($language->id == wire('user')->language->id) {
				$out.= "<li class='$hreflang'>";
			} else {
			$url = $page->localUrl($language); 
			$hreflang = $page->getLanguageValue($language, 'name'); 
			$out.= "<a hreflang='$hreflang' href='$url'>$language->title</a></li>";


	$out .= "</ul>";
	return $out; 


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...