I realize that content editor web parts can utilize audience targeting in the full version of SharePoint. I'd like to go one step further and actually target content within my CEWP to specific groups.

Example: I have a "navigation" CEWP that displays icons and links. I realize that this same functionality can be recreated using the quick launch, however users do not respond as well to the quick launch as they do to big shiny buttons.

enter image description here

I would like to keep all the navigation buttons in a single CEWP. I'd also like to trim certain cells out of my table according to the security group membership of the user viewing the page. I realize this can be done with permission levels (using SPSecurityTrimmedControl) but that isn't useful to me since there could be multiple groups that need the same level of access to the CEWP.

Since SharePoint has the ability to do this natively, is there a way to place the same functionality into a content editor webpart and do this at an even finer level?

4 Answers 4


You can extend the SPSecurityTrimmedControl class to create a custom control that discriminates based on group membership rather than permission level.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.WebControls;
using System.Web.UI;
using Microsoft.SharePoint;

namespace My.Custom.Controls
    public class SPGroupTrimmedControl : SPSecurityTrimmedControl
        private List<string> _groups = new List<string>();

        public string Groups
                return string.Join(";", _groups.ToArray());
                _groups.AddRange(value.Split(new char[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries));

        protected override void Render(HtmlTextWriter output)
            if (!string.IsNullOrEmpty(Groups) && UserInGroup())

        private bool UserInGroup()
            SPUser user = SPContext.Current.Web.CurrentUser;

            // show admins all content
            if (user.IsSiteAdmin)
                return true;

            bool isInGroup = false;
            foreach (string groupName in _groups)
                string trimmedGroupName = groupName.Trim();
                int groupID = SPContext.Current.Web.Groups[trimmedGroupName].ID;
                if (SPContext.Current.Web.IsCurrentUserMemberOfGroup(groupID))
                    isInGroup = true;
            return isInGroup;

and then:

<%@ Register TagPrefix="mycontrols" Namespace="My.Custom.Controls" Assembly="My.Custom.SPGroupTrimmedControl, Version=, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" %>


<mycontrols:SPGroupTrimmedControl runat="server" ID="MyGroupTrimmer" Groups="Group 1;Group 2">

    // your trimmed content


ETA: In my own implementation of this, I have a custom method to check if a user is a member of a group rather than using SPWeb.IsCurrentUserMemberOfGroup, so this code, as is, is untested. And I'd just like to point out that the line

int groupID = SPContext.Current.Web.Groups[trimmedGroupName].ID;

could potentially throw an exception if the group is not present on the site, so you might want to throw in a little error handling around that.

  • This looks excellent! I will give it a test drive :) Thank you!
    – Shrout1
    Commented Aug 19, 2014 at 16:16

Well, to me it seems this should be pretty easily done with a custom content editor webpart.

  1. Create a new Webpart and have it derive from the Content Editor webpart.
  2. Add a custom action to the rich text editor so that you can use to easily inject an additional wrapper xml element surrounding the pieces of html you want to target.

  3. Use this XML element to hook into your Content XmlElement property of the CEWP in serverside code so that it transforms the result based on the following property: "SPContext.Current.Web.DoesUserHavePermission(SPBasePermissions.ManageLists)" -> Wrote this by hand, check it.

I haven't done this before, but it seems pretty feasible.

Wrapper examples:

... your code ...


<SPSecurity data-group="Owners" data-webpermissions="ManageLists">
... your code ...

This seems pretty similar to what I encountered yesterday. It's not within the CEWP but you could use a script editor that uses css to hide the element and target that to whichever audience(s) of your liking.

Target audience for a stylesheet


This seems like it would be natively supported in a Content Query Web Part. It would require some rework on your part to add your links and thumbnails to a list, configure the CQWP slots, and style the CQWP appropriately but at least you know it works and is possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.