Jump to content

Adding an ICON to Menu


Recommended Posts

Hi All,

Been messing around with this for a while but it's not working.  Time to as k the experts!!

I have a hook that displays LOGIN only when people are logged out. However, I want to add a Font Awesome icon to the menu item.

This is the current code:

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $primaryNavbar)
{
   $client = Menu::context('client'); 

   if (is_null($client)) {
	   
	   $primaryNavbar->addChild('Login')
        ->setUri('https://www.webssiteking.com/clientarea.php/')
        ->setOrder(70);
   }
	
});

I tried adding the below but that just causes the menu item to disappear altogether!

->setIcon('fa-shopping-cart');

So, if I want to add an icon next to a menu created in a hook, how should one do this?

Thanks in advance.

Brad

Edited by sanechoice
Link to comment
Share on other sites

  • WHMCS Staff

Hi @sanechoice,

When using the setIcon() method, do ensure that you're including the full font awesome class.

For example:

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $primaryNavbar)
{
   $client = Menu::context('client'); 

   if (is_null($client)) {
	   
	   $primaryNavbar->addChild('Login')
           ->setUri('https://www.webssiteking.com/clientarea.php/')
           ->setIcon('fas fa-shopping-cart');
           ->setOrder(70);
   }
	
});

I have not tested this, and this example was provided personally by myself to assist you in resolving the issue.

Let me know if you still run in to any issue.

Link to comment
Share on other sites

On 13/07/2019 at 20:26, sanechoice said:

Been messing around with this for a while but it's not working.  Time to ask the experts!!

don't worry, i'm here - beware of pale imitations leading you up the wrong garden path. headshake.gif

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $primaryNavbar) {

	$client = Menu::context('client'); 
	if (is_null($client)) {
		$primaryNavbar->addChild('Login', array(
			'label' => Lang::trans('Login'),
			'icon' => 'fa-lock',
			'uri' => 'clientarea.php',
			'order' => 70,
		));
	}
});
1 hour ago, WHMCS Peter said:

When using the setIcon() method, do ensure that you're including the full font awesome class.

you shouldn't need to unless you're using something other than FAS - but throw it in if you think you need to.

1 hour ago, WHMCS Peter said:

I have not tested this, and this example was provided personally by myself to assist you in resolving the issue.

I hope this isn't a sign of the future with Support staff posting code but then immediately disclaiming it... 🙄

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