Jump to content

How to display or hide content based on user groups


Go to solution Solved by opentype,

Recommended Posts

Posted

Hello,

I was wondering if anyone could tell me how to display content based on certain user groups.

For example. I have a few custom pages where I use the WYSIWYG editor to display information. I would like that some texts/images/links were ONLY visible to certain user groups. Is there an easy way to hide/show content in a widget based on the user groups I want?

Thanks yoj

Posted

Of course these are the blocks themselves, rather than text within a block. Which would certainly be the better way to go. There is no built in way to hide text within a block 

Posted
19 hours ago, opentype said:

You need to create those blocks in the ACP (as Pages blocks) instead of the frontend. That way, you get full permissions for every block. The respective block type is Custom → Editor. 

Thanks a lot, makes sense.

My problem is that I have many user groups and wanted to create a block where a certain link or image will be displayed only IF user group = X. Otherwise, I will have to create dozens of pages just to display a different link or image.

  • Solution
Posted

For an image, I would probably just check the user group with PHP and then load an image with that user group as file name. 

{{if \IPS\Member::loggedIn()->member_group_id}}
{{$group_id = \IPS\Member::loggedIn()->member_group_id}}
<img src="https://myserver.com/assets/group_{$group_id}}.jpg">
{{endif}}

Then just upload the images: group_5.jpg, group_6.jpg, group_7.jpg. 

Pay attention to caching as well. If the block is cached for all user groups, users would see the wrong images regardless of the PHP check. 

The same method could be used to load different blocks based on user groups. It doesn’t have be separate pages. 

Posted
3 hours ago, opentype said:

For an image, I would probably just check the user group with PHP and then load an image with that user group as file name. 

{{if \IPS\Member::loggedIn()->member_group_id}}
{{$group_id = \IPS\Member::loggedIn()->member_group_id}}
<img src="https://myserver.com/assets/group_{$group_id}}.jpg">
{{endif}}

Then just upload the images: group_5.jpg, group_6.jpg, group_7.jpg. 

Pay attention to caching as well. If the block is cached for all user groups, users would see the wrong images regardless of the PHP check. 

The same method could be used to load different blocks based on user groups. It doesn’t have be separate pages. 

Thank you soooooooo much!

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...