EscalateSEO Posted October 5, 2015 Share Posted October 5, 2015 When editing sidebars in v6, the code looks similar to this: ->getChild('Order New Services') ->setUri('http://www.google.com'); Is there a way to set the specified URL to open in a new tab? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 5, 2015 Share Posted October 5, 2015 (edited) yes, add the following ->getChild('Order New Services') ->setAttribute('target', '_blank') ->setUri('http://www.google.com'); Edited October 5, 2015 by sentq 0 Quote Link to comment Share on other sites More sharing options...
EscalateSEO Posted October 5, 2015 Author Share Posted October 5, 2015 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' )); } 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 5, 2015 Share Posted October 5, 2015 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'); } 0 Quote Link to comment Share on other sites More sharing options...
Manchester Web Hosting Posted October 20, 2015 Share Posted October 20, 2015 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? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 20, 2015 Share Posted October 20, 2015 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 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 20, 2015 Share Posted October 20, 2015 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! 0 Quote Link to comment Share on other sites More sharing options...
Manchester Web Hosting Posted October 21, 2015 Share Posted October 21, 2015 Thanks for the very quick replies! you need a proof? here it is http://forum.whmcs.com/showthread.ph...ghlight=_blank 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 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 21, 2015 Share Posted October 21, 2015 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', )); }); 0 Quote Link to comment Share on other sites More sharing options...
Manchester Web Hosting Posted October 28, 2015 Share Posted October 28, 2015 Just want to say a 'BIG' THANKYOU @brian! such a simple solution once you know how.. and @sentq examples are on the spot 0 Quote Link to comment Share on other sites More sharing options...
gbotica Posted November 5, 2015 Share Posted November 5, 2015 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. 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.