I'd like to override Placeholder method @Html.Sitecore().Placeholder("keyName").

I want to achieve special behaviour to update CustomData (Editable checkbox in Placeholder item) value.

Eventhough Placeholder item sets editable as true, specific users would not be able to edit Custom Data.

Here is my code, but doesn't work.

public class CustomPlaceholder : SitecoreHelper
    public CustomPlaceholder(System.Web.Mvc.HtmlHelper htmlHelper)
        : base(htmlHelper)

    public override HtmlString Placeholder(string placeholderName)
        Sitecore.Diagnostics.Assert.ArgumentNotNull(placeholderName, "placeholderName");
        using (Sitecore.Mvc.Common.ContextService.Get().Push(this.HtmlHelper.ViewContext))
            var stringWriter = new System.IO.StringWriter();
            var args = new Sitecore.Mvc.Pipelines.Response.RenderPlaceholder.RenderPlaceholderArgs(placeholderName, stringWriter, this.CurrentRendering);

            //if (user belongs to LimitedContent role) {
            //    args.CustomData["editable"] = false;
            //} else {
            //    args.CustomData["editable"] = true;

            return new HtmlString(stringWriter.ToString());
  • 1
    Have you thought about how you could do this with permissions? I'm not in front of my computer right now so I can't test this but if you created a role that broke inheritance on the Placeholder item, placed all your users in this role, then, gave other roles explicit permissions on the Placeholder item, would this not accomplish what you are trying to do with code?
    – DougCouto
    Dec 6, 2016 at 23:05
  • 1
    I did, but the behavior is different. For example, if you deny READ access in specific role, they still can add new control in the empty placeholder. If you set Editable as False, the user can't delete the control in the placeholder and they also can't add another control in the same placeholder. The updating permission could be easiest way, but not what I want to do.
    – Nas
    Dec 7, 2016 at 1:22
  • What Sitecore version are you on? Dec 7, 2016 at 8:06
  • It is v8.0 rev update6
    – Nas
    Dec 7, 2016 at 14:42


Your Answer

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

Browse other questions tagged or ask your own question.