Jump to content

adding images to nav menu


Recommended Posts

can this be used with Glyphicons?

yes.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $PrimaryNavbar)
{
   if(!is_null($PrimaryNavbar->getChild('Home'))){
               $PrimaryNavbar->getChild('Home')
               ->setIcon('glyphicon-home');
   }
});

hnNLsA1.png

 

Also, with
fa-server

is there a way to remove the top 2 servers on the image output ?

not with code - those I suppose you could edit an icon and resave it as something else... http://birchenough.co.uk/edit-font-awesome-icon-add-font-awesome-font/

 

two other things to contemplate...

 

1. there's little to stop you from adding a png image to a child label (in navbar or sidebar)...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $PrimaryNavbar)
{
   if(!is_null($PrimaryNavbar->getChild('Home'))){
               $PrimaryNavbar->getChild('Home')
               ->setLabel('<img src="homeicon.png"> '.Lang::trans('clientareanavhome'));
   }
});

es5ozNs.png

 

2. or if you want to be adventurous... (ab)using setIcon to load any specific png image instead of a fontawesome/glyphicon image...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $PrimaryNavbar)
{
   if(!is_null($PrimaryNavbar->getChild('Store'))){
               $PrimaryNavbar->getChild('Store')
               ->setIcon('fa-shopicon');
   }
});

and then in navbar.tpl,

 

{if $item->hasIcon()}<img src="{$item->getIcon()|replace:'fa fa-':''}.png"> {/if}

... with a similar change to $childitem too - though I suspect you'd have to ensure the icons were all the same size. otherwise you may get layout issues.... the same should work for sidebars too (with the same size proviso).

 

gTj49D2.png

Link to comment
Share on other sites

  • 4 years later...
On 7/19/2017 at 11:39 AM, brian! said:

yes.

 


<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $PrimaryNavbar)
{
   if(!is_null($PrimaryNavbar->getChild('Home'))){
               $PrimaryNavbar->getChild('Home')
               ->setIcon('glyphicon-home');
   }
});
 

 

 

hnNLsA1.png

 

 

 

not with code - those I suppose you could edit an icon and resave it as something else... http://birchenough.co.uk/edit-font-awesome-icon-add-font-awesome-font/

 

two other things to contemplate...

 

1. there's little to stop you from adding a png image to a child label (in navbar or sidebar)...

 

 


<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $PrimaryNavbar)
{
   if(!is_null($PrimaryNavbar->getChild('Home'))){
               $PrimaryNavbar->getChild('Home')
               ->setLabel('<img src="homeicon.png"> '.Lang::trans('clientareanavhome'));
   }
});
 

 

 

es5ozNs.png

 

 

 

2. or if you want to be adventurous... (ab)using setIcon to load any specific png image instead of a fontawesome/glyphicon image...

 

 


<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $PrimaryNavbar)
{
   if(!is_null($PrimaryNavbar->getChild('Store'))){
               $PrimaryNavbar->getChild('Store')
               ->setIcon('fa-shopicon');
   }
});
 

 

and then in navbar.tpl,

 

 


{if $item->hasIcon()}<img src="{$item->getIcon()|replace:'fa fa-':''}.png"> {/if}
 

 

... with a similar change to $childitem too - though I suspect you'd have to ensure the icons were all the same size. otherwise you may get layout issues.... the same should work for sidebars too (with the same size proviso).

 

 

gTj49D2.png

 

 

Hey,

How do i add custom image and name on the menu?

Example: Menu named Home and having image as well?

Link to comment
Share on other sites

  • 3 weeks later...
26 minutes ago, Businezz said:

Hi, it doesn't work me. I do use Lagom template.... 

important to have mentioned the Lagom use.... once you use custom themes, then the options will be different.

On 17/09/2021 at 05:07, Businezz said:

How do i add custom image and name on the menu?

i'll add a font awesome icon to the Store menu.....

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $PrimaryNavbar) {
	
	if (!is_null($PrimaryNavbar->getChild('Store'))) {
		$PrimaryNavbar->getChild('Store')->setLabel('<i class="fas fa-shopping-cart"></i> '.Lang::trans('navStore'));
	}
});

7GJpiPX.png

I would therefore assume you can use the <img> option instead of a FA icon in a setLabel - but no doubt you'll let me know if that doesn't work!

it might also be simpler to use absolute paths to any images to ensure you're calling them.

...and with regards to adding "Home" to the home navbar icon, it's already there - but it's hidden by default in the CSS, so that should be a quick CSS fix to show it.

B5kmO6x.png

Link to comment
Share on other sites

On 10/3/2021 at 2:07 PM, brian! said:

important to have mentioned the Lagom use.... once you use custom themes, then the options will be different.

i'll add a font awesome icon to the Store menu.....


<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $PrimaryNavbar) {
	
	if (!is_null($PrimaryNavbar->getChild('Store'))) {
		$PrimaryNavbar->getChild('Store')->setLabel('<i class="fas fa-shopping-cart"></i> '.Lang::trans('navStore'));
	}
});

7GJpiPX.png

I would therefore assume you can use the <img> option instead of a FA icon in a setLabel - but no doubt you'll let me know if that doesn't work!

it might also be simpler to use absolute paths to any images to ensure you're calling them.

...and with regards to adding "Home" to the home navbar icon, it's already there - but it's hidden by default in the CSS, so that should be a quick CSS fix to show it.

B5kmO6x.png

Hey, this hook replaced the label and not the icon.... I am using vertical menus BTW on the left if that helps 🙂

Also, how can i add different images for all the menus? Thanks!!!!

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