Page 1 of 1

No modules on Home page?

Posted: Mon May 11, 2009 8:49 am
by vang
Sorry if this has already been discussed, but my searches are returning zero results.

I do not want modules to display on the home page, but, of course, I'd like them to display on all the other pages of the site. There doesn't seem to be a setting for this in the admin, so I'm guessing I'd have to hard -code it?

What would be the best way to solve this situation?

Modifying the common/home.tpl only modifies the main content section.
Modifying the common/layout.tpl, if I remove the code here it removes the modules for the whole site.

I was thinking of using an "if then" statement, but do not know what I should call.

Here's an example of some wrong code (which doesn't call any errors, but doesn't work either):

Code: Select all

// START Vang's IF THEN Statement

 <?php if ($content == 'common/home.tpl') { ?>
            <div id="content"><?php echo $content; ?></div>

      <?php } else { ?>       

Code: Select all

// Modules loaded here

  <div id="column_left">
    <?php foreach ($modules as $module) { ?>
    <?php if ($module['position'] == 'left') { ?>
    <?php echo ${$module['code']}; ?>
    <?php } ?>
    <?php } ?>
  </div>
  <div id="column_right">
    <?php foreach ($modules as $module) { ?>
    <?php if ($module['position'] == 'right') { ?>
    <?php echo ${$module['code']}; ?>
    <?php } ?>
    <?php } ?>
  </div>
  <div id="content"><?php echo $content; ?></div>

// END Modules

Code: Select all

// END of Vang's IF THEN Statement

<?php } ?>
Does anyone have any ideas on what would be the best route of approach?
Thanks everyone for your input. ;)

Re: No modules on Home page?

Posted: Mon May 11, 2009 8:40 pm
by MikoElSuperbeasto
Here my solution i used for an integration in yourtheme/common/layout.tpl :

Code: Select all

<? if(sizeof($breadcrumbs) <= 1) {  ?>Home page show<? } ?>
I simply check if the breadcumbs size array is less or egal to 1, if so, we are on the homepage. So you can play with it to hide/show the left or right column.

Re: No modules on Home page?

Posted: Tue May 12, 2009 10:10 am
by vang
Wow! Thanks a bunch for your help MikoElSuperbeasto! ;D
That was exactly what I needed.
In case anyone else needs this bit of info, here is the <body> section of yourtemplate/common/layout.tpl

Code: Select all

<body>
<div id="container">
  <div id="header"><?php echo $header; ?></div>
  <div id="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>

// START No Modules on Home page 
<?php if (sizeof ($breadcrumbs) <= 1) { ?> 
  <div id="content"><?php echo $content; ?></div>
<?php } else { ?>  
// No Modules on Home page 

  <div id="column_left">
    <?php foreach ($modules as $module) { ?>
    <?php if ($module['position'] == 'left') { ?>
    <?php echo ${$module['code']}; ?>
    <?php } ?>
    <?php } ?>
  </div>
  <div id="column_right">
    <?php foreach ($modules as $module) { ?>
    <?php if ($module['position'] == 'right') { ?>
    <?php echo ${$module['code']}; ?>
    <?php } ?>
    <?php } ?>
  </div>
  <div id="content"><?php echo $content; ?></div>

// No Modules on Home page 
  <?php } ?>
// END No Modules on Home page 

  <div id="footer"><?php echo $footer; ?></div>
</div>
</body>
This will remove the left and right modules from your home page, but they will still be present on the subsequent pages.
Thanks again MikoElSuperbeasto for your help and for the code!
BTW, I tried it like it you posted without the php in the markup (e.g. <? instead of <?php ) and it didn't work.
I had to include php to the markup.
My guess is it is dependant upon the version of php?
Anyhow, I hope someone else finds this useful.
If you can't get it to work correctly, try copying all of the code and replacing your code from <body> to </body>.
Enjoy! ;D

Re: No modules on Home page?

Posted: Tue May 12, 2009 10:08 pm
by jnixus
Couldnt that be due to short tag config not configured?

Re: No modules on Home page?

Posted: Wed May 13, 2009 7:30 am
by phpuk
A lot of servers these days have short tags turned off as it is seen as bad coding practice anyway.

Bloody purists.

Phil.

Re: No modules on Home page?

Posted: Wed Jul 29, 2009 5:46 pm
by Avi
Awesome, this is exactly what I was looking for. I'm now working on having other things only appear on the homepage, ill try to send a link and copies of the code when i'm done.

thank you!

(p.s. used joomla for a loooong time, so happy i found opencart!)

Re: No modules on Home page?

Posted: Tue Feb 08, 2011 3:16 am
by balaphp
Hi friends
i recently developed module controller . This module is used to determine in which pages your modules should be displayed. for more info see this link http://www.opencart.com/index.php?route ... on_id=1411

Thanks