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.

 

Condense code: else if's

Condense code: else if's

This IS working but would like to condense it:

if (
$option == 'com_hotproperty'
and $view == 'types'
and $id == '1'
and $Itemid == '65'
and JRequest::getVar('layout') == 'properties'
) return;
else;
if (
$option == 'com_hotproperty'
and $view == 'types'
and $id == '2'
and $Itemid == '65'
and JRequest::getVar('layout') == 'properties'
) return;
else;
if (
$option == 'com_hotproperty'
and $view == 'types'
and $id == '3'
and $Itemid == '65'
and JRequest::getVar('layout') == 'properties'
) return;
else;
if (
$option == 'com_hotproperty'
and $view == 'types'
and $id == '4'
and $Itemid == '65'
and JRequest::getVar('layout') == 'properties'
) return;
else;
if (
$option == 'com_hotproperty'
and $view == 'types'
and $id == '5'
and $Itemid == '65'
and JRequest::getVar('layout') == 'properties'
) return;
else;
if (
$option == 'com_hotproperty'
and $view == 'types'
and $id == '6'
and $Itemid == '65'
and JRequest::getVar('layout') == 'properties'
) return;
else;
if (
$option == 'com_hotproperty'
and $view == 'types'
and $id == '7'
and $Itemid == '65'
and JRequest::getVar('layout') == 'properties'
) return;
else;
if (
$option == 'com_hotproperty'
and $view == 'types'
and $id == '8'
and $Itemid == '65'
and JRequest::getVar('layout') == 'properties'
) return;
else;
if (
$option == 'com_hotproperty'
and $view == 'types'
and $id == '9'
and $Itemid == '65'
and JRequest::getVar('layout') == 'properties'
) return;
else;
if (
$option == 'com_hotproperty'
and $view == 'types'
and $id == '10'
and $Itemid == '65'
and JRequest::getVar('layout') == 'properties'
) return;

else return 113;

I attempted and $id == "1,2,3,4,5,6,7,8,9,10'
didn't work...

Thank you!

zbabyface
Beginner Modder
ranks
useravatar
Offline
5 Posts
User info in posts
Administrator has disabled public posting

Re: Condense code: else if's

Ok, how about this version:

if (
  $option == 'com_hotproperty'
  and $view == 'types'
  and JRequest::getVar('layout') == 'properties'
) {
  $exclusions = array(1,2,3,4,5,6,7,8,9,10);
  if (in_array( $id, $exclusions )) return;
}
return 113;

Or, even simpler since you are using ids 1 to 10 consecutively:

if (
  $option == 'com_hotproperty'
  and $view == 'types'
  and JRequest::getVar('layout') == 'properties'
  and $id >= 1 and $id <= 10
) return;
return 113;


I deliberately left out the Itemid check, as that is equivalent to checking for the menu item. If you assign the MetaMod to only that menu item, then it's redundant in the PHP. If you assign the MetaMod to ALL menu items, then it might be useful to not check for the Itemid, so that the rule will catch the URLs even if the Itemid gets screwed up.

Hope that helps,
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
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1680
Total Polls:
6
Total Posts:
5914
Total Posts Today:
1
User Info:
 
Total Users:
10831
Newest User:
bluesky1
Members Online:
0
Guests Online:
186

Online: 
There are no members online

Forum Legend:

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