Home > members > Members only conditional

Members only conditional

June 12Hits:7

Is there a better way to write this?

{if logged_in_group_id == "1" || logged_in_group_id == "6" || logged_in_group_id == "7" || logged_in_group_id == "11"} Hello Members... {/if} 

It seems very long.

Version 2.9.0


Well, you don't say what version of EE you're using, so I'm gonna assume v2, though this solution should work just fine in v3 too.

the quickest method would be PHP's in_array() function, which you can use in your template natively, however so that I don't give a PHP answer first here's a plugin that adds in_array to EE :


{if '{exp:in_array value=“2” array="1|6|7|11"}'}
  Hello Members...

If you rather add plugins that should get you there, you can shorten your EE tags as well, as group_id will be 0 for non logged in members :

{if group_id == '1' || group_id == '6' || group_id == '7' || group_id == '11'}
  Hello Members...

Or if you're not afraid of a bit o PHP and the parse order :

EE v2.X

<?php if ( in_array( ee()->session->userdata('group_id') , array ( 1, 6, 7, 11 ) ) ) { ?>
  Hello Members...
<?php } ?>

EE v3.X

  global $SESS;
  if ( in_array( $SESS->userdata('group_id') , array ( 1, 6, 7, 11 ) ) ) {
    Hello Members...
<?php } ?>

To add to Blatant's comprehensive answer and keeping native without PHP...

{if "|1|6|7|11|" *= "|".logged_in_group_id."|"} ... {/if}

Advanced Conditionals

Related Articles

  • Members only conditionalJune 12

    Is there a better way to write this? {if logged_in_group_id == "1" || logged_in_group_id == "6" || logged_in_group_id == "7" || logged_in_group_id == "11"} Hello Members... {/if} It seems very long. Version 2.9.0 --

  • How to get rid of semantic duplicationMay 26

    I am breaking my head with how to get rid of semantic duplication(Code that is syntactically the same but does different things). I can't find anywhere a post or something that mentions a bit how to refactor this kind of duplication. All I found was

  • Optional base class template to get conditional data membersAugust 21

    In generic code, I sometimes want to conditionally add a data member to a class template. Writing separate template specializations scales as 2^N for N conditional data members. Absent a static_if feature, I have found the following user-defined clas

  • return false if one of members fails a conditionJuly 15

    I want to validate a list of objects for example strings. and if one of the objects fails to pass the condition return false as validation result . this is the code I use : public static bool AreValid(string[] strs) { foreach (string str in strs) { i

  • Returning null value in Model members causing object reference error

    Returning null value in Model members causing object reference error January 11

    I have some code and when it executes, it throws a NullReferenceException, saying: Object reference not set to an instance of an object. What does this mean, and what can I do about it? --------------Solutions------------- What is the cause? Bottom L

  • How to create different menu's for not logged in visitors and for logged in members?March 4

    I'm creating a website which will provide services to members and I want to make it so that when a not logged in person comes to the website the menu is specifically designed for sales pages to make him register, but when a logged in person comes in

  • conditional statement for profile pagesMarch 10

    I'm using different headers for in my wordpress/buddypress setup and I need a conditional statement for member pages. So everything that comes after mysite.com/members/. How do I do that with something like is_page()? --------------Solutions---------

  • Drupal Commons on D6 - Visibility of 'Group members' and 'Latest group activity' blocksApril 13

    Out of the box the 'Group members' and 'Latest group activity' blocks on the main page of a group are visible to all users regardless of whether one is a member of that group or not. How can both blocks be displayed only when a user is a member of th

  • Unit testing multiple conditions in an IF statement

    Unit testing multiple conditions in an IF statementJuly 6

    I have a chunk of code that looks something like this: function bool PassesBusinessRules() { bool meetsBusinessRules = false; if (PassesBusinessRule1 && PassesBusinessRule2 && PassesBusinessRule3) { meetsBusinessRules= true; } return meets

  • Prevent AD users from seeing group members?August 22

    I need to prevent users from looking up the membership of groups that they are not members of. So for example, Bob is in GroupA but not GroupB, so if Bob were to look at properties in AD he would see all the members of GroupA but non of the members o

  • What level of detail to use in an interface members descriptions?August 30

    I am extracting interfaces from some classes in .NET, and I am not completely sure about what level of detail of description to use for some of the interface members (properties, methods). An example: interface ISomeInterface { /// <summary> /// Che

  • Terms and conditions for a simple website September 26

    Possible Duplicate: When does a website require a privacy policy and/or terms of use? I finished building a website for an online chess club which I am a member of. This is my first website. The site has blogging feature so the members can log in and

  • Nagios3: Conditional operators for service checks?October 8

    I'm trying to setup Nagios to monitor my various machines using hostgroups to define 'machine roles', against which I run services to check the machines by role. However, I'd like to use conditional operators that would enable me to run the service c

  • How can I allow a member to register a limited number of other members?January 4

    I am in need of a voting solution for one of my clients that will give members UP TO four votes, and no more. I have looked over the usual polling modules on devot:ee and all of them either allow for single votes or multiple votes, but not up to a sp

  • Views Filter 2 Content types but with condition on one of them

    Views Filter 2 Content types but with condition on one of themJanuary 8

    I looked up this one before posting: Views filter criteria multiple content types (Drupal 7) And even though the problem is the same, the solutions provided do not seem to work. I have Content Types A and B. B has a boolean field. I need to filter an

  • Conditional for newest item in a loop limited to oneJanuary 9

    You probably looked at the title and said, "what the heck?". I have this on a detail page, a loop limiting to 1, but I want to conditionally do something for the newest item. {if count == 1} won't help me here because it's already limited to 1.

  • Ways method to protect members profile edit pages?February 1

    Just looking at finding the best ways ways to protect member profile editing pages. I have members profiles set up under a template structure such as members/profile/{member_id}/sub-page Thats is fine, all these pages are public. I do however show, o

  • Conditional Formatting: if the value matches one of theseMarch 21

    I'm using a multi-author field (VZ Members) that outputs this for author IDs; 4333|3871|3957 How can I show entries that match the logged in user? Something like: If logged_in_member_id matches one of these, 4333|3871|3957, then show entry. Is there

  • SharePoint Designer 2010 Workflow not emailing SharePoint Group membersAugust 28

    SharePoint is returning a "Coercion warning: user or group does not have a valid e-mail address." when I attempt to target a SharePoint Group with users inside it via a SharePoint Designer 2010 Workflow. Here are the steps I have performed: Setu

  • Is there a way to block access to member profile pages so only logged in members can see them?September 10

    I've had a few run-ins with that spam attack that is often used against Exp Eng sites which creates endless member accounts for the sole purpose of adding links back to whatever the spammers are trying to promote. The Member's URL in the member profi

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.497 s.