Jump to content

Editing sidebars in v6


EscalateSEO

Recommended Posts

Not working on my end - here's the original code:

 

    if (!is_null($primarySidebar->getChild('Service Details Actions'))) {

       $primarySidebar->getChild('Service Details Actions')->addChild('Sidebar', array(
           'label' => 'Web Link',
           'uri' => 'http://www.google.com',
           'order' => '100'
       ));
   }

Link to comment
Share on other sites

try to replace the original code with:

if (!is_null($primarySidebar->getChild('Service Details Actions'))) {

   $primarySidebar->getChild('Service Details Actions')->addChild('WebLink')
   ->setLabel('Web Link')
   ->setUri('http://www.google.com')
   ->setAttribute('target', '_blank');
}

Link to comment
Share on other sites

  • 2 weeks later...
try to replace the original code with:

if (!is_null($primarySidebar->getChild('Service Details Actions'))) {

   $primarySidebar->getChild('Service Details Actions')->addChild('WebLink')
   ->setLabel('Web Link')
   ->setUri('http://www.google.com')
   ->setAttribute('target', '_blank');
}

 

Yes BUT how do you add the attribute without replacing the whole coce? Here: http://docs.whmcs.com/Editing_Client_Area_Menus (adding social media panel) it for example shows how to add in your social media links. However it missing the _blank attribute. So whats the correct syntax to add that in WITHOUT changing the whole code for what you posted previously? trying to keep to WHMCS code as much as possible!

 

Secondly, what IF I only wanted to place that new sidebar panel on clientarea homepage ONLY, what syntax would I then need to add into the hook?

 

Can you help here at al? @brian seems to be quite a good coder perhaps he could shed some light on this too? :)

Link to comment
Share on other sites

Yes BUT how do you add the attribute without replacing the whole coce? Here: http://docs.whmcs.com/Editing_Client_Area_Menus (adding social media panel) it for example shows how to add in your social media links. However it missing the _blank attribute. So whats the correct syntax to add that in WITHOUT changing the whole code for what you posted previously? trying to keep to WHMCS code as much as possible!

 

Secondly, what IF I only wanted to place that new sidebar panel on clientarea homepage ONLY, what syntax would I then need to add into the hook?

 

Can you help here at al? @brian seems to be quite a good coder perhaps he could shed some light on this too? :)

you need a proof? here it is http://forum.whmcs.com/showthread.php?105202-v6-02-Menu-How-to-add-Link-Target-Attribute&highlight=_blank

Link to comment
Share on other sites

Yes BUT how do you add the attribute without replacing the whole coce? Here: http://docs.whmcs.com/Editing_Client_Area_Menus (adding social media panel) it for example shows how to add in your social media links. However it missing the _blank attribute. So whats the correct syntax to add that in WITHOUT changing the whole code for what you posted previously? trying to keep to WHMCS code as much as possible!

you just need to identify which child link you're talking about and change the attribute... as an example, the following hook will change the "Order New Services" link to open in a new tab/window - but it doesn't change the existing link, only the attribute.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
   if (!is_null($secondarySidebar->getChild('Client Shortcuts'))) {
            $secondarySidebar->getChild('Client Shortcuts')
                           ->getChild('Order New Services')
                           ->setAttribute('target', '_blank');
   }
});

 

Secondly, what IF I only wanted to place that new sidebar panel on clientarea homepage ONLY, what syntax would I then need to add into the hook?

a good example of that will be the sidebar hook sentq posted in the thread below... that adds a sidebar to clientarea on all pages...

 

http://forum.whmcs.com/showthread.php?106891-Display-Credit-Balance-In-Six-Template

 

but if you wanted it only on the clientarea homepage, you could tweak it using...

 

    $filename = basename($_SERVER['REQUEST_URI'], ".php");
   $querystring = $_SERVER['QUERY_STRING'];
   $parseFile = explode('.', $filename);
   $client = Menu::context("client");
   $clientid = intval($client->id);

   if ($parseFile['0']!=='clientarea' || $clientid===0 || $querystring !=''){
       return;
   }

 

@brian seems to be quite a good coder perhaps he could shed some light on this too? :)

"quite a good coder" - i'm no sentq, but i'll take that! :)

Link to comment
Share on other sites

Thanks for the very quick replies!

 

 

So forgive me if I am getting ths wrong BUT when I add in the socialmedia panel hook file I THEN need to add another hook file to add the target attribute? so I have in essence 2 hook files for the 1 task? My initial question was to try and get everything into one hook file OR do I just add that additional code to the bottom of my socialmedia hook file? sorry for not understanding this correctly. A bit rusty on my smarty/php code when it comes to WHMCS!

 

you just need to identify which child link you're talking about and change the attribute... as an example, the following hook will change the "Order New Services" link to open in a new tab/window - but it doesn't change the existing link, only the attribute.

 

Again as i explained above. 2 hook files? in the samefile? or am i missing something again?

 

 

a good example of that will be the sidebar hook sentq posted in the thread below... that adds a sidebar to clientarea on all pages...

 

http://forum.whmcs.com/showthread.ph...n-Six-Template

 

.

 

Cool many thanks for the code @senqt downloaded and will be using as an example ;)

 

but if you wanted it only on the clientarea homepage, you could tweak it using...

 

Thanks @brain! will try this implementation too :)

Link to comment
Share on other sites

So forgive me if I am getting this wrong BUT when I add in the socialmedia panel hook file I THEN need to add another hook file to add the target attribute? so I have in essence 2 hook files for the 1 task? My initial question was to try and get everything into one hook file OR do I just add that additional code to the bottom of my socialmedia hook file? sorry for not understanding this correctly. A bit rusty on my smarty/php code when it comes to WHMCS!

you add the additional code to the child you want to modify - you should only need one hook...

 

as a quick example, here's the socialmedia sidebar hook code from the documentation, but i've modified the facebook link to open in a new tab/window...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

// Add social media links to the end of all secondary sidebars.
add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar)
{
   // Add a panel to the end of the secondary sidebar for social media links.
   // Declare it with the name "social-media" so we can easily retrieve it
   // later.
   $secondarySidebar->addChild('social-media', array(
       'label' => 'Social Media',
       'uri' => '#',
       'icon' => 'fa-thumbs-up',
   ));

   // Retrieve the panel we just created.
   $socialMediaPanel = $secondarySidebar->getChild('social-media');

   // Move the panel to the end of the sorting order so it's always displayed
   // as the last panel in the sidebar.
   $socialMediaPanel->moveToBack();

   // Add a Facebook link to the panel.
   $socialMediaPanel->addChild('facebook-link', array(
       'uri' => 'https://facebook.com/our-great-company',
       'label' => 'Like us on Facebook!',
       'order' => 1,
       'icon' => 'fa-facebook',
   ));
   $socialMediaPanel->getChild('facebook-link')
                    ->setAttribute('target', '_blank');

   // Add a Twitter link to the panel after the Facebook link.
   $socialMediaPanel->addChild('twitter-link', array(
       'uri' => 'https://twitter.com/ourgreatcompany',
       'label' => 'Follow us on Twitter!',
       'order' => 2,
       'icon' => 'fa-twitter',
   ));

   // Add a Google+ link to the panel after the Twitter link.
   $socialMediaPanel->addChild('google-plus-link', array(
       'uri' => 'https://plus.google.com/1234567890123456',
       'label' => 'Add us to your circles!',
       'order' => 3,
       'icon' => 'fa-google-plus',
   ));
});

Link to comment
Share on other sites

FYI ... you don't need to use getChild() to grab the facebook link after adding it, you can just append the setAttribute() to the addChild() function, like this:

 

<?php
$socialMediaPanel->addChild('facebook-link', array(
       'uri' => 'https://facebook.com/our-great-company',
       'label' => 'Like us on Facebook!',
       'order' => 1,
       'icon' => 'fa-facebook',
   ))->setAttribute('target', '_blank');
?>

 

Hope that helps.

 

- - - Updated - - -

 

Secondly, what IF I only wanted to place that new sidebar panel on clientarea homepage ONLY, what syntax would I then need to add into the hook?

 

I recently had the need for this too, I found this to be the best solution:

 

// Add custom sidebar menu to the bottom of the client area homepage ONLY
if (App::getCurrentFilename() == 'clientarea') {

// is the 'action' empty, i.e. we're on the client area home page
   	if (!empty(trim($_GET['action']))) { return; }

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) {

	// set your menu items here

});

}

 

Hope that helps.

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