How to hide the maincontent on specific pages

 

Some users have requested the possibity to hide the maincontent, especially for the home page. I will show you a simple method that works into Template Creator CK and that don't need to edit the template files manually.

You will be able to use this technique directly in the interface and then adapt the code to what you want to hide the maincontent block (or any other block) on the pages you want.

 

1/ Add the custom code in the HEAD

Edit your template and go in the top menu Parameters >> Custom Code. Copy paste or write the following code and Validate :

<?php
// Detecting Home
$menu = JFactory::getApplication()->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
    $siteHome = 1;
}else{
    $siteHome = 0;
}
?>

This code will be added directly before the closing tag </head>. It will check if you are on the homepage, according the default menu item that you have set in your website. the variable $siteHome will have the value 1 if you are visiting the homepage.

 

2/ Add the custom blocks for the condition

 

In the template edition interface, take a new Custom Block and drag and drop it directly before the Maincontent block. Take another Custom Block and put it just after the Maincontent block. Your maincontent block must now have a custom block just before and just after it.

 

2.1/ in the first custom block, add this code to begin the condition :

<?php if(! $siteHome) { ?>

This will check the value of the $siteHome, here if were are NOT in the homepage, then we can display the maincontent. This means that the maincontent will be hidden on the homepage only.

 

2.2/ in the second custom block, add this code to close the condition :

 <?php } ?>

This will simply mark the end of the condition that we have started before.

 

3/ Preview your template

 

To test this method, you must first Download your template and install it into your website, then assign it by default. You can then test this method, go in the homepage >> the maincontent block will not be shown.