OptimusBain Posted November 28, 2022 Posted November 28, 2022 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
opentype Posted November 28, 2022 Posted November 28, 2022 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. OptimusBain 1
Marc Posted November 28, 2022 Posted November 28, 2022 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Â
opentype Posted November 28, 2022 Posted November 28, 2022 For more complex scenarios, I create the blocks as HTML and then call blocks from within blocks. That would allow more granular permissions or conditions like {{ if in membergroup}} show x {{endif}} Marc and OptimusBain 1 1
OptimusBain Posted November 29, 2022 Author Posted November 29, 2022 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 opentype Posted November 29, 2022 Solution Posted November 29, 2022 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. OptimusBain 1
Marc Posted November 29, 2022 Posted November 29, 2022 Thank you for that extra info there, opentype 🙂 OptimusBain 1
OptimusBain Posted November 29, 2022 Author Posted November 29, 2022 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!
Recommended Posts