Forum Discussion
Show/Hide a button webpart in sharepoint online based on group of logged in user
Hi Guys,
I need recommendation on a requirement that I have regarding controlling visiblity of a "button" webpart in SharePoint based on the M365 group of the logged in user.
For example if logged in user belongs to M365 Group A, then hide the button webpart, whereas show it when the logged in user belongs to the M365 Group B.
This is the button webpart that I want to conditionally show/hide based on group that logged in user belongs to
I have done some basic research and my understanding is that :
1. Only some type of webparts can be "Target audienced", and button webpart does not fall in that category
2. It may be possible to show or hide button webpart based on a javascript code. However I am unable to see any "content editor" or "Script editor" webpart, when trying to add it to a SP page containing that button webpart.
If point 2 above is the only option to conditionally hide button webpart,pls advice how can I go about it (how to embed code in this page based on a script that can get the parameters such as M365 group id, webpart id etc)
- Instead of using the button web part, could you use the Quick Links web part in a button layout? The Quick Links web part supports audience targeting as well as choosing to open the link (or not) in a new tab. This would get your outcome with no special code required - just a different web part that does support targeting.
- Instead of using the button web part, could you use the Quick Links web part in a button layout? The Quick Links web part supports audience targeting as well as choosing to open the link (or not) in a new tab. This would get your outcome with no special code required - just a different web part that does support targeting.
- Glad it helped! There is another "hack" that I used to use before you could choose to open Quick Links in a new tab. You can create a 1 column/1 row table and add text that opens in a new window. It looks like a button, but it's really just a table column. One of the nice things about this approach is that you can take advantage of the different color options in table styles. But the button layout of Quick Links looks better!