1

I am writing a custom GetAllowedRenderings processor, but I cannot see how to obtain the current item that I'm editing in the experience editor.

There doesn't seem to be a property on the GetPlaceholderRenderingsArgs args and Sitecore.Context.Item is null.

How can I get the current item in this context?

  • It is expected. Getting allowed renderings is executed for placeholder, not for item. That is why there is no context item. Why do you need context item? Do you want to show different allowed controls depending on page in Experience Editor mode? – Anton Dec 14 '17 at 13:08
  • Yes - we have a generic grid layout, but I only want to allow certain controls if the page is of a certain template.. – David Masters Dec 14 '17 at 13:11
2

It will require customization of Sitecore pipelines:

  1. Override Sitecore.Pipelines.GetChromeData.GetPlaceholderChromeData processor in getChromeData pipeline. It should call getPlaceholderRenderings pipeline with transferring Context page in PlaceholderRenderingsArgs. Use CustomData property or create your own pipeline arguments class.
  2. Access from your custom GetAllowedRenderings processor to CustomData property with Context and use it.
  • Thanks. It's a bit awkward because I already have a DynamicPlaceholder implementation overriding this, but it makes sense. – David Masters Dec 14 '17 at 14:12
  • Hmm, I've tried this and initially it appeared to work, but it seems that the GetPlaceholderChromeData is only called on page load, and it isn't called when clicking on the "Add here" button on a placeholder. Which means my customData is not set when the GetAllowedRenderings processor fires. Is the getPlaceholderRenderings pipeline called from elsewhere? – David Masters Dec 14 '17 at 15:30
2

In the end I did a combination of Anton's suggestion as well as extending the Sitecore.Shell.Applications.WebEdit.Commands.AddRendering command.

It turns out that the getPlaceholderRenderings pipeline is invoked from the GetPlaceholderChromeData processor (as Anton suggested) and the Sitecore.Shell.Applications.WebEdit.Commands.AddRendering command. Without passing in the context item from the latter it would be be null when clicking the 'Add here' button in the experience editor.

Unfortunately the AddRendering command is difficult to extend because it's methods are all protected/private static, so I had to de-compile it and paste the code into a new version adding the following line to the RunGetPlaceholderRenderingsPipeline method:

placeholderRenderingsArgs.CustomData["CurrentItem"] = Client.GetItemNotNull(context["contextitempath"]);

Then I just needed to add the new command via a config patch:

<commands>
  <command name="webedit:addrendering" type="Sitecore.Shell.Applications.WebEdit.Commands.AddRendering, Sitecore.ExperienceEditor">
    <patch:attribute name="type">Foundation.RestrictedRenderings.Infrastructure.Commands.AddRendering, Foundation.RestrictedRenderings</patch:attribute>
  </command>
</commands>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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