Some time ago I described how to implement an “Edit Fields” Button without defining all fields. Now we have a look at the implementation for the rendering properties. For this we also implement a command, but need one step more.
We first had a look into Sitecore’s implementation and found the class Sitecore.Shell.Applications.WebEdit.Commands.EditRenderingProperties. Unfortunately we had to copy it and do our changes. But first we decided to implement our own RenderingParameters. You can find the whole code in the github repository.
Following you find our overwritten method for the command: it’s the rendering parameters.
namespace Foundation.ExperienceEditor.Commands
{
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Shell.Applications.WebEdit.Commands;
using Sitecore.Web;
using Sitecore.Web.UI.Sheer;
/// <summary>
/// Represents an enhanced version of <see cref="
/// Sitecore.Shell.Applications.WebEdit.Commands.EditRenderingProperties"/>.
/// </summary>
public class EditRenderingPropertiesCommand : EditRenderingProperties
{
#region Protected Methods
/// <summary>
/// Copied from <see cref="
/// Sitecore.Shell.Applications.WebEdit.Commands.EditRenderingProperties"/>
/// class.
/// </summary>
/// <param name="context"></param>
/// <remarks>
/// Changed <see cref="
/// Sitecore.Shell.Applications.Layouts.DeviceEditor.RenderingParameters"/>
/// to <see cref="AMRenderingParameters"/> class.
/// </remarks>
protected override void Run(ClientPipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
int @int = MainUtil.GetInt(args.Parameters["selectedindex"], -1);
if (@int < 0)
{
return;
}
Item clientContentItem = WebEditUtil.GetClientContentItem(
Client.ContentDatabase);
CustomRenderingParameters renderingParameters =
new CustomRenderingParameters
{
Args = args,
DeviceId = args.Parameters["device"],
SelectedIndex = @int,
HandleName = args.Parameters["handle"],
Item = clientContentItem
};
if (renderingParameters.Show())
{
if (args.HasResult)
{
string sessionString =
WebUtil.GetSessionString(args.Parameters["handle"]);
sessionString = GetLayout(sessionString);
SheerResponse.SetAttribute(
"scLayoutDefinition", "value", sessionString);
SheerResponse.Eval(
"window.parent.Sitecore.PageModes.ChromeManager.handleMessage(
'chrome:rendering:propertiescompleted');");
}
else
{
SheerResponse.SetAttribute(
"scLayoutDefinition", "value", string.Empty);
}
WebUtil.RemoveSessionValue(args.Parameters["handle"]);
}
}
#endregion
}
Once you have implemented the C# part, it’s time to enhance the Javascript. We edited the /sitecore/shell/Applications/Page Modes/ChromeTypes/RenderingChromeType.js. In the handleMessage method we added the following case:
/* Added custom command for calling SitecoreCommand from JS*/
case "chrome:rendering:runcommand":
this.runcommand(params.command, sender);
break;
And then we added the code for the runcommand method:
/* runs the passed Sitecore Command which has to be defines in the Commands.config */
runcommand: function (commandName, sender)
{
Sitecore.PageModes.PageEditor.layoutDefinitionControl().value =
Sitecore.PageModes.PageEditor.layout().val();
var controlId = this.controlId();
if (sender)
{
controlId = sender.controlId();
}
Sitecore.PageModes.PageEditor.postRequest(
commandName +
"(uniqueId=" + this.uniqueId() + ",controlId=" + controlId + ")");
},
And now we add the command in the config.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<commands>
<command name="webedit:customeditrenderingproperties" type="Foundation.ExperienceEditor.Commands.EditRenderingPropertiesCommand, Foundation.ExperienceEditor" />
</commands>
</sitecore>
</configuration>
Last but not least: We define the command item in the core DB.

And that’s all. Now you can add the button to your rendering if you want.
You can find the repository on github, where both commands are implemented in the solution.