Jump to content

Recommended Posts

Looking at the new bootstrap six template.

I'm confused to where the nav and sidebar links are being fetched from.

 

Header.tpl

<section id="main-menu">

   <nav id="nav" class="navbar navbar-default  navbar-main" role="navigation">
       <div class="container">
           <!-- Brand and toggle get grouped for better mobile display -->
           <div class="navbar-header">
               <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                   <span class="sr-only">Toggle navigation</span>
                   <span class="icon-bar"></span>
                   <span class="icon-bar"></span>
                   <span class="icon-bar"></span>
               </button>
               <a class="navbar-brand" href="#">Brand</a>
           </div>

           <!-- Collect the nav links, forms, and other content for toggling -->
           <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

               <ul class="nav navbar-nav">

                   {include file="$template/includes/navbar.tpl" navbar=$primaryNavbar}

               </ul>

               <ul class="nav navbar-nav navbar-right">

                   {include file="$template/includes/navbar.tpl" navbar=$secondaryNavbar}

               </ul>

           </div><!-- /.navbar-collapse -->

 

The links seems to be collected from navbar.tpl But you can't edit the actual links

navbar.tpl

{foreach $navbar as $item}
   <li{if $item->hasChildren()} class="dropdown"{elseif $item->getClass()} class="{$item->getClass()}"{/if} id="{$item->getId()}">
       <a {if $item->hasChildren()}class="dropdown-toggle" data-toggle="dropdown" href="#"{else}href="{$item->getUri()}"{/if}>
           {if $item->hasIcon()}<i class="{$item->getIcon()}"></i> {/if}
           {$item->getLabel()}
           {if $item->hasBadge()} <span class="badge">{$item->getBadge()}</span>{/if}
           {if $item->hasChildren()} <b class="caret"></b>{/if}
       </a>
       {if $item->hasChildren()}
           <ul class="dropdown-menu">
           {foreach $item->getChildren() as $childItem}
               <li{if $childItem->getClass()} class="{$childItem->getClass()}"{/if} id="{$childItem->getId()}">
                   <a href="{$childItem->getUri()}">
                       {if $childItem->hasIcon()}<i class="{$childItem->getIcon()}"></i> {/if}
                       {$childItem->getLabel()}
                       {if $childItem->hasBadge()} <span class="badge">{$childItem->getBadge()}</span>{/if}
                   </a>
               </li>
           {/foreach}
           </ul>
       {/if}
   </li>
{/foreach}

 

When this is loaded on a page it shows as

   <!-- Collect the nav links, forms, and other content for toggling -->
           <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

               <ul class="nav navbar-nav">

                       <li id="Primary_Navbar-Home">
       <a href="index.php">
                       Home
                               </a>
           </li>
   <li id="Primary_Navbar-Announcements">
       <a href="announcements.php">
                       Announcements
                               </a>
           </li>
   <li id="Primary_Navbar-Knowledgebase">
       <a href="knowledgebase.php">
                       Knowledgebase
                               </a>
           </li>
   <li id="Primary_Navbar-Network_Status">
       <a href="serverstatus.php">
                       Network Status
                               </a>
           </li>
   <li id="Primary_Navbar-Contact_Us">
       <a href="contact.php">
                       Contact Us
                               </a>
           </li>


               </ul>

 

So where are the links to edit/add to? IE

         <li id="Primary_Navbar-Home">
       <a href="index.php">
                       Home
                               </a>
           </li>

 

Maybe I'm missing something simple it's been a long day. I know I can obviously take the include out and add my own links to the section but it's annoying me.

 

Thanks in advance.

Share this post


Link to post
Share on other sites
Maybe I'm missing something simple it's been a long day. I know I can obviously take the include out and add my own links to the section but it's annoying me.

must have been a long day - you posted in thee wrong forum! :)

 

perhaps the docs page below might help...

 

http://docs.whmcs.com/Editing_Client_Area_Menus

 

I won't be installing the beta until tomorrow, so I haven't tried it yet.

Share this post


Link to post
Share on other sites

Hi,

How do I change the nav bar links when a client is logged into the client area? ie. the nav bar is different when not logged in and when logged in - any examples?

Share this post


Link to post
Share on other sites

I used

$ca = new WHMCS_ClientArea();
and then with
$ca->isLoggedIn()
I decide wether to add/remove/whatever. Dunno if this is the correct way to do it, but I could not find any example or documentation about this matter.

Share this post


Link to post
Share on other sites

Thanks Hal9000, would you have a code example so we can see it in context?

Share this post


Link to post
Share on other sites

I'm really confused about why the complex hooks for just editing the menus as well. I've just spent 30 minutes trying to figure out how to modify the knowledgebase link...Hal9000 it would really be good to see more of your example code.

Edited by wrender

Share this post


Link to post
Share on other sites

From what I can see it looks like you need to do an if statement for whether or not the person is logged into WHMCS, and then do a menu hook. Here is what ended up working for me. Hope it helps someone.

 

1. Create a file in /includes/hooks/yourhookname.php

 

2. Use this code

 

<?php

 

$ca = new WHMCS_ClientArea();

 

use WHMCS\View\Menu\Item as MenuItem;

 

# Check login status

 

if ($ca->isLoggedIn()) {

 

# User is logged in - put any code you like here

 

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

{

$primaryNavbar->getChild('Support')

->getChild('Announcements')

->setUri('https://www.yourwebsite.com/blog');

$primaryNavbar->getChild('Support')

->getChild('Knowledgebase')

->setUri('https://www.yourwebsite.com/knowledge-base');

});

 

}

else {

 

# User is not logged in

 

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

{

$primaryNavbar->getChild('Announcements')

->setUri('https://www.yourwebsite.com/blog');

$primaryNavbar->getChild('Knowledgebase')

->setUri('https://www.yourwebsite.com/knowledge-base');

});

 

 

}

 

*This seems to error on logout for some reason. Still trying to figure out why....

Edited by wrender

Share this post


Link to post
Share on other sites

this will add a new link to primarynavbar after open ticket and only be there when your logged in

hope it helps someone out.

 

<?php

$ca = new WHMCS_ClientArea();

use WHMCS\View\Menu\Item as MenuItem;



if ($ca->isLoggedIn()) {



add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
$primaryNavbar->addChild('Example')
->setUri('https://www.example.com')
->setOrder(70);
});

} 
add_hook("ClientAreaPrimaryNavbar");

?>

Share this post


Link to post
Share on other sites

I just removed the entire menu from displaying to someone who's not logged in.

Share this post


Link to post
Share on other sites
I just removed the entire menu from displaying to someone who's not logged in.

 

Thanks SteveV. That was a good suggestion. As a temporary solution I've removed the menu from users that are not logged in as well by using a smarty if statement in header.tpl.

 

Hoping someone can clarify how to properly call the menu items based on logged in, logged out, and after logging out (which is where I get the error message).

 

Cheers

Edited by wrender

Share this post


Link to post
Share on other sites

When trying to remove from navbar dropdowns from logged in navbar when you click logout it shows error because its trying to remove the dropdown nav from the not logged in navbar so shows error that it doesn't exist thats how i see it anyway because error is

Fatal error: Call to a member function removeChild() on a non-object in /home/username/public_html/mysite.com/whmcs/includes/hooks/removesupportdropdown.php on line 8

 

but while logged in the hook does remove the dropdowns.

Share this post


Link to post
Share on other sites
When trying to remove from navbar dropdowns from logged in navbar when you click logout it shows error because its trying to remove the dropdown nav from the not logged in navbar so shows error that it doesn't exist thats how i see it anyway because error is

 

 

but while logged in the hook does remove the dropdowns.

 

Yes. That is correct. I wonder how we could go about fixing this.

Share this post


Link to post
Share on other sites

Get them to remove the stupid hooks be a start but cant see that so id say if theres no bit code can add to hook they should rename the not logged in navbar instead of it being called the same inside and out.

Share this post


Link to post
Share on other sites

In case this helps anyone. I ended up just doing this in the custom.css file for now, until these hooks are properly documented. Just disable the list items in CSS.

 

#Primary_Navbar-Support-Knowledgebase, #Primary_Navbar-Support-Announcements, #Primary_Navbar-Support-Downloads {

display: none;

}

 

#Secondary_Sidebar-Support-Announcements, #Secondary_Sidebar-Support-Knowledgebase, #Secondary_Sidebar-Support-Downloads {

display: none;

}

Share this post


Link to post
Share on other sites

Thanks for the tips. I was 95% there but just needed to sort the logged in bit working.

 

All looks good, but I do get an error on logout. Any suggestions on how to resolve that?

Share this post


Link to post
Share on other sites

When a menu item doesn't exist, the getChild method will return false, so if you're working with a menu that only displays conditionally based on login status, here is the recommended way to do it:

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild('Support'))) {
       $primaryNavbar->getChild('Support')->removeChild('Announcements');
   }
});

 

And if you wanted a menu item to only be displayed for logged in users, you can use the menu context to control that:

 

<?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('Example')
           ->setUri('https://www.example.com/')
           ->setOrder(100);
   }
});

 

 

This page in our documentation should help you with working with the nav bars: http://docs.whmcs.com/Client_Area_Navigation_Menus_Cheatsheet

Share this post


Link to post
Share on other sites

Thanks - how does one open ->setUri('https://www.example.com/') in a new window?

Share this post


Link to post
Share on other sites

I'm working on something similar, I'm trying to remove the cPanel login button for reseller packages but the variable $type doesn't appear to be available. Is there a way I can structure the menu based on package type? So far I've got:

 

<?php
#modify Sidebar menu 

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{

  if (!is_null($primarySidebar->getChild('Service Details Actions')) && (!is_null($type)) && ($type != 'hostingaccount')  ) {
       $primarySidebar->getChild('Service Details Actions')->removeChild('Login to cPanel');
  }

});

 

 

Any ideas welcome! Thank you :-) Edith

Edited by Terra

Share this post


Link to post
Share on other sites

Edith,

 

the answer is going to be similar to the code in the thread below..

 

http://forum.whmcs.com/showthread.php?104894-Login-to-cPanel-amp-Webmail-on-Client-Product-Details&p=435091#post435091

 

except you'll want to remove child rather than changing the links - untested, but I think you could use the code below to find $type...

 

$type = $service->product->type;

  • Like 1

Share this post


Link to post
Share on other sites

Hi Brian - fab, thank you, yes, that's working!

 

<?php
#modify Sidebar menu 

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{

$service = Menu::context('service'); 
$type = $service->product->type;  

  if (!is_null($primarySidebar->getChild('Service Details Actions')) && ($type!="hostingaccount")  ) {
       $primarySidebar->getChild('Service Details Actions')->removeChild('Login to cPanel');
  }


});

 

Love this forum - high five! Edith

Share this post


Link to post
Share on other sites
@brian! @Matt ?

I like the order you thought of us in! :)

 

are you talking about nav menus or sidebars?

 

can you not add a child with '--------------' or '_____________' as a label with no link?

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines