Jump to content

Hide left sidebar only from a single template


lizzus

Recommended Posts

Hello everyone. I have been using whmcs 7. I have been using whmcs for several years and so over time I have seen various changes. I use whmcs for various purposes and for each purpose a different template is used, called with? Systpl = templatename from the associated website. For a specific template (and only for this), which uses template six as a development basis, I would like to remove the sidebars on the left. I have seen that it is possible to act with hooks to remove sidebars, but it is not clear to me both where and how to add strings and if these also affect the other installed templates. Thank you.

Link to comment
Share on other sites

18 hours ago, lizzus said:

For a specific template (and only for this), which uses template six as a development basis, I would like to remove the sidebars on the left.

sounds like you have 3 options - modify the template (probably not the specific one, but header), use CSS to hide the sidebars (easy for one, probably not worth it if you want to hide an entire column of them) or use a hook.

18 hours ago, lizzus said:

I have seen that it is possible to act with hooks to remove sidebars, but it is not clear to me both where and how to add strings and if these also affect the other installed templates.

it's entirely possible to write hooks that will only work on one specific page, and also if it's only using one specific theme (e.g Six, but not default, five etc).

which template and sidebars are you wanting to remove ?

Link to comment
Share on other sites

I have 5 different template. Every template has different header, footer, content end some customization. I need only for one of these remove completely (or hide) the left sidebar. What do you suggest me? More simple? I want hide left sidebar everywhere in this template. Thank for you help.

Link to comment
Share on other sites

you could nuke all sidebars for a specific theme, e.g Six, by using the action hook below...

<?php

# Nuclear Sidebar Removal
# Written by brian!

function nuclear_remove_Sidebars_hook($vars) {
	
	GLOBAL $smarty;
	$template = $smarty->getVariable('template');
	if ($template == "six") {
		$primarySidebar = Menu::primarySidebar();
		$primarykids = $primarySidebar->getChildren();
		$secondarySidebar = Menu::secondarySidebar();
		$secondarykids = $secondarySidebar->getChildren();
		foreach ($primarykids as $Sidebar) {
			$primarySidebar->removeChild($Sidebar);
		}
		foreach ($secondarykids as $Sidebar) {
			$secondarySidebar->removeChild($Sidebar);
		}
	}
}	
add_hook("ClientAreaSidebars",1,"nuclear_remove_Sidebars_hook");

function cart_remove_sidebars_hook($vars) {	

	if ($vars['inShoppingCart'] && $vars['template'] == "six") {
		$head_return = "<style>#order-standard_cart .cart-body { width:100% !important; }
		.cart-sidebar {display: none;}</style>";
		return $head_return;
	}
}
add_hook("ClientAreaHeaderOutput",1,"cart_remove_sidebars_hook");

that would work on all pages - the sidebars would be removed and the page width of the content adjusted to fill the space.... except in the cart, e.g standard_cart, where you might need to employ an additional hook to adjust the widths - both hooks are in the code above.

note if your custom Six theme isn't called Six, then you will have to adjust those values in the above hook.

I suspect there might be a simpler way using template edits or CSS, but I had the above hooks already written, so they should be enough for your situation.

Link to comment
Share on other sites

Hi,

Also I want to remove the left sidebar from all "cart.php" pages.

I tried to remove the next "include" from some .tpl templates but not working (this only remove sidebar in other pages, not in "cart.php" pages):

{include file="orderforms/standard_cart/sidebar-categories.tpl"}

Anybody knows which file I need edit for remove sidebar only in "cart.php" pages (when a client are in order process)?.

Thank you!

Link to comment
Share on other sites

Thank you so much for your support. 4 quick questions:
1. this code I add it in a file filename.php in the directory / includes / hook /. Do I have to give them a particular name?
2. How do I call it in the template?
3. Do I have to create two separate files (one for the template and one for the shopping cart)?
4. Can I use an if variable ($ template == "tpl1" || $ template == "tpl2") for use it for 2 template?

Link to comment
Share on other sites

52 minutes ago, lizzus said:

1. this code I add it in a file filename.php in the directory / includes / hook /. Do I have to give them a particular name?

Correct.

53 minutes ago, lizzus said:

2. How do I call it in the template?

You don't.  WHMCS calls the hook when the page is being created. 

53 minutes ago, lizzus said:

3. Do I have to create two separate files (one for the template and one for the shopping cart)?

Both hooks can go in the same file or separate if you want -- up to you.

55 minutes ago, lizzus said:

4. Can I use an if variable ($ template == "tpl1" || $ template == "tpl2") for use it for 2 template?

You should be able to do that without issue. 

Link to comment
Share on other sites

Perfect Brian! Works fine. Only in "cart.php?a=view"i have a blank part (where was sidebar). I checked file templates/orderform/mycustomcart/viewcart.tpl finding issue but i not find it.

 

Schermata-2021-05-12-alle-23.00.50.jpg

Edited by lizzus
Link to comment
Share on other sites

12 hours ago, lizzus said:

1. this code I add it in a file filename.php in the directory / includes / hook /. Do I have to give them a particular name?

includes/hooks

12 hours ago, lizzus said:

Perfect Brian! Works fine. Only in "cart.php?a=view"i have a blank part (where was sidebar). I checked file templates/orderform/mycustomcart/viewcart.tpl finding issue but i not find it.

that would imply that at viewcart, the second hook isn't working.. there are a number of reasons why that might happen.... which version of WHMCS are you using ?

you could try changing the line of code to...

if (($vars['inShoppingCart'] || $vars['templatefile'] == "viewcart") && $vars['template'] == "six") {

and see if that fixes the issue.... remember to change "six" to whatever your custom theme is called.

Link to comment
Share on other sites

25 minutes ago, lizzus said:

Hi Brian and thanks again. I'm using version 7.10.2. 

that explains it - try replacing the second hook with this...

function cart_remove_sidebars_hook($vars) {	

	if ($vars['inShoppingCart'] && $vars['template'] == "six") {
		$head_return = "<style>#order-standard_cart .col-md-9 { width:100% !important; } </style>";
		return $head_return;
	}
}
add_hook("ClientAreaHeaderOutput",1,"cart_remove_sidebars_hook");

again, change six to your custom theme name.

Edited by brian!
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