Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Hide a module based on two if statements?

Hide a module based on two if statements?

Since I'm not familiar with PHP I'm kind of lost. I've looked through the available recipes, but haven't been able to make anything useful to accomplish my need.

I initially had my main login module only visible on pages where the usertype was "Public Frontend". That worked fine. Now I have a second login module on a page that will only be accessible from a link I send in an email. It's a different login module because this particular one will redirect to a specific page.

The problem is on the special page it shows both login modules.. I first thought I could just combine the page id detection to not show the default login module on the page id that the special login module appears, but in my efforts I haven't been successful. I tried using or statements among other things, but I'm sure I'm just doing it wrong.

The two separate pieces of code I have been trying to combine are below. Any help or direction would be appreciated. Thanks.

Code:

if ($user->usertype == "" || $user->usertype == "Registered") return 116;


if ( !(
$option == 'com_content'
and $view == 'article'
and $id == '102'
and $Itemid == 'null'
and JRequest::getVar('layout') == 'default' /*!*/
)) return 116;

kevinh81
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Re: Hide a module based on two if statements?

So I ended up figuring out one way of doing it. Accidental I'm sure tongue

Code:


if (!(( MM_LOGGED_IN ) || ($option == 'com_content'
and $view == 'article'
and $id == '102'
and $Itemid == 'null'
and JRequest::getVar('layout') == 'default'))) return 116;

This works. But if there is a better more correct way to be doing, I'm open. Thanks.

kevinh81
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Re: Hide a module based on two if statements?

Hi Kevin,

The format of your rule is basically correct and should work fine. But just for the record I'll give you a slightly simpler rule that will do the same thing.

Code:

if (MM_NOT_LOGGED_IN

  and !(
    $option == 'com_content'
    and $view == 'article'
    and (int)$id == 102
    )
   ) return 116;

The Itemid line wasn't necessary (and null should not be in quotes), and the layout parameter wan't necessary either. I took the integer value of the $id variable because under some circumstances the $id value can equal '102:title here', so it's a little safer to convert to an integer which strips off any other text after the digits.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1698
Total Polls:
6
Total Posts:
5944
Posts this week:
4
User Info:
 
Total Users:
5533
Newest User:
gregg25476
Members Online:
1
Guests Online:
121

Online: 
gregg25476

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked