Jump to content

Nav Links


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.

Link to comment
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.

Link to comment
Share on other sites

  • 2 months later...

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
Link to comment
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
Link to comment
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");

?>

Link to comment
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
Link to comment
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.

Link to comment
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.

Link to comment
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;

}

Link to comment
Share on other sites

  • WHMCS CEO

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

Link to comment
Share on other sites

  • 2 months later...

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
Link to comment
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;

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

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