HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Help using if_in_group comcode tag

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#100644 (In Topic #19763)
Avatar

Community saint

Hi,

I want to display different sections on a page dependant on usergroup membership.

I added

Code

[if_in_group="Paid Member" type="secondary"] [/if_in_group]
around the section that I want to display if the user is a Paid Member - this works as expected.

Now I want to be able to display a different block of text if the user is not a member of the Paid Members group.

The docs (ocPortal Tutorial: Filtering using ocFilter syntax - ocPortal.com) say that I can use a ! to indicate a negative filter.

So I would expect

Code

[if_in_group="!Paid Member" type="secondary"] [/if_in_group]
to work - but it does not, in fact the section this surrounds does not display whether the user is in the Paid Members group or not.

What am I missing ?

I guess what I really want is a IF THEN ELSE construct.

Can anyone set me on the right path please.

Cheers
Ade
Back to the top
 
Posted
Rating:
#100647
Avatar

Hi,

I've just applied a few little fixes to this, as things weren't connecting up ideally in the code. I won't go into details, because actually the real problem here wasn't the little issues I found, but a small error in your syntax…

Code

[if_in_group="*,!Paid Member" type="secondary"][/if_in_group]

It is necessarily to select everything, then deselect. Otherwise you are just saying you don't want something, but not saying you do want anything.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#100659
Avatar

Community saint

Hi Chris,

I have just given this a go:

It does not seem to matter whether I have this:

Code

[if_in_group="Paid Member" type="secondary"]I am a paid member[/if_in_group]

or this

Code

[if_in_group="*,!Paid Member" type="secondary"]I am not a paid member[/if_in_group]

For someone in the Paid Member group I get both lines outputted.
For someone not in the Paid Member group I do not get any output.

Cheers
Ade
Back to the top
 
Posted
Rating:
#100660
Avatar

Ah, sorry, I'm confusing myself and you.

My example said "anything except paid member", which will be true if a member is in any other group additionally to paid member.

ocFilter was not designed for negative conditions as such, it was just designed to be able to limit what the positive conditions are.

You will need to use Tempcode.

Try, {+START,IF,{$NOT,{$IS_IN_GROUP,14}}}...{+END}.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#100661
Avatar

I just edited my post, $IS_IN_GROUP needs IDs, names are not supported (because its a bad performance choice; the Comcode layer converts to IDs automatically, but Tempcode is lower-level).


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#100662
Avatar

Adding to the docs…

Not

It is important to understand that "!" does not really mean 'not', it means 'avoid' or 'except'. There is no way to use ocFilter to match on a negative, you can only limit what positive matches are accepted.

Let's say we want to match anyone not in usergroup #14 using the Tempcode IS_IN_GROUP symbol, which happens to work via ocFilter.

Attempt 1

Code

{+START,IF,{$IS_IN_GROUP,!14}}...{+END}
This is incorrect, because we haven't defined any positive matches.

Attempt 2

Code

{+START,IF,{$IS_IN_GROUP,*,!14}}...{+END}
This is also incorrect, because it would match if a member happened to be in another group additionally to usergroup #14.

Attempt 3

Code

{+START,IF,{$NOT,{$IS_IN_GROUP,14}}}...{+END}
Finally, this is correct. It negates the ocFilter after it runs, via the Tempcode NOT symbol.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#100663
Avatar

Community saint

I'll give that ago Chris.

Is there an easy way to get the Group ID's ?

I cannot see them on the URL.

Looked in a few places - do I need to look in the database tables to find them ?

Cheers
Ade
Back to the top
 
Posted
Rating:
#100664
Avatar

If you look on the edit URL for the group you'll find them there.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: