Brad (SaneChoice Limited) Posted July 13, 2019 Share Posted July 13, 2019 (edited) 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 July 13, 2019 by sanechoice 0 Quote Link to comment Share on other sites More sharing options...
Remitur Posted July 14, 2019 Share Posted July 14, 2019 (edited) There's a setIcon method to apply to get what you need: https://docs.whmcs.com/classes/7.6/WHMCS/View/Menu/Item.html After having set setIcon method, you can check all the attributes of the menu item tto see how and why it's not working (I guess you need to setup both icon and label...) Edited July 14, 2019 by Remitur 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted July 14, 2019 WHMCS Staff Share Posted July 14, 2019 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. 0 Quote Link to comment Share on other sites More sharing options...
Brad (SaneChoice Limited) Posted July 14, 2019 Author Share Posted July 14, 2019 Thanks Guys. But still not joy. I used @WHMCS Peter's code and, again, the menu item disappears the minute I add this line: ->setIcon('fas fa-shopping-cart'); As soon as I remove that line, the LOGIN text menu appears again. Any ideas? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 14, 2019 Share Posted July 14, 2019 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. <?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... 🙄 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.