Jump to content

change menu url depending the language


Recommended Posts

Anyone know what is the language variable i have to use with an IF so i can point to different url depending the language selected in WHMCS?

 

Thanx!

 

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $navItem = $primaryNavbar->getChild('Contact Us');
   if (is_null($navItem)) {
       return;
   }

   $navItem->setUri('https://www.domain.net/contact');

});

Link to comment
Share on other sites

Thanx but is not working :-(

 

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $navItem = $primaryNavbar->getChild('Contact Us');
   if (is_null($navItem)) {
       return;
   }
 if ($_SESSION['language']=="spanish") {
   $navItem->setUri('https://www.domain.net/es/contacto');
 }
 else {
  $navItem->setUri('https://www.domain.net/contact');
 }

});

Link to comment
Share on other sites

try with the SESSION variable

lol - I figured out three different methods to attempt this last night... but none of them would work 100% - I didn't even think of checking the session! :roll:

 

unfortunately, as plus says, this session trick doesn't quite work... Language isn't in the session at the start.

 

I wrote the hook below to test sentq's idea...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
if ($_SESSION['Language']=="english") {
   $contactlink = "http://www.google.co.uk";
}
elseif ($_SESSION['Language']=="french") {
   $contactlink = "http://www.google.fr";
}
else {
   $contactlink = "http://www.google.com";
}  
   if (!is_null($primaryNavbar->getChild('Contact Us'))) {
             $primaryNavbar->getChild('Contact Us')
                           ->setUri($contactlink);
   }

});

by default, it doesn't work because Language doesn't exist... so it will set the contact link to google.com

 

however, as soon as you select a language from the menu, Language is in the session and the contact link then changes based on the language chosen. :idea:

 

so it's nearly there - we just need some guaranteed way to get the initial value of language.. perhaps pulling it from the Smarty variable would be one way, but maybe sentq has an alternative ?

Edited by brian!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated