Are you still making your content author to edit the content of a page using content editor? then stop.
For content author in Sitecore the best way for them to edit a page is to use Sitecore Experience Editor. This way they can focus on editing the content on the page with visual indication what would their changes would look like. However there are some cases where content can’t be edited on the page because they are not displayed on the page itself, Metadata information is such a case.
There are some guide already out there to set up an edit meta data button in page editor in Sitecore 7 and below, and here I would like to do the same in Sitecore 8. This is based on the guide that I’ve found on http://blog.istern.dk/2015/03/02/running-sitecore-field-editor-from-a-speak-command-in-sitecore-experience-editor/ which can be reused to create other type of functionality.
First you need to install Sitecore Rocks, because in Sitecore 8 the interface is built using SpeakUI you may find it quite different with how you usually set up a new button in Sitecore 7 and below. I’ve also found it easier to create a SpeakUI component using Sitecore Rocks, so you definitely should check it out. After you’ve installed Sitecore Rocks and setup a connection to the Sitecore website you should see the following screen.
Expand the core database and go to sitecore->content->applications->webedit->ribbons->webedit
Here you can see a couple of familiar strips which is what being displayed on the experience editor
We want to add a new button to edit meta data here, so go in Sitecore Rocks and under the WebEdit node follow this steps
- Add a new Page Properties strip
- Add a new item with the template of Strip.
- Set the header to “Page Properties” and the ID to “PagePropertiesStrip”
- In Sitecore Rocks select tasks and design layout then add a new rendering of type Strip
- Add a new Hidden Content chunk
- Under the new Page Properties strip add a new item with the template of Chunk
- Set the header to “Hidden Content” and ID to “HiddenContentChunk”
- In Sitecore Rocks select tasks and design layout then add a new rendering of type Chunk
- Add a new Edit Meta data button
- Under the new Hidden Content chunk
- Set the header to “Edit Meta Data” and ID to “EditMetaDataButton”
- In Sitecore Rocks select tasks and design layout then add a new rendering of type LargeButton
- Edit the rendering properties of the LargeButton
- Set AccessKey to Meta Keywords|Meta Description (this the meta data fields that I’ve setup in Sitecore)
- Set the Click property to trigger:button:click
- Set the Command to LaunchFieldEditor
- Set the PageCodeScriptFileName to the path of the LaunchFieldEditor.js file is
What it currently looks like so far
At this stage we still need to register the command to handle the edit meta data button functionality so let’s go ahead and do that.
1 2 3 4 5 6 7 |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <sitecore.experienceeditor.speak.requests> <request name="ExperienceEditor.GenerateFieldEditorUrl" type="Website.Modules.Components.ExperienceEditor.FieldEditor.GenerateFieldEditorUrl, Website.Modules" /> </sitecore.experienceeditor.speak.requests> </sitecore> </configuration> |
The GenerateFieldEditorUrl class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
public class GenerateFieldEditorUrl : PipelineProcessorRequest<ItemContext> { public string GenerateUrl() { var fieldList = CreateFieldDescriptors(RequestContext.Argument); var fieldeditorOption = new FieldEditorOptions(fieldList); //Save item when ok button is pressed fieldeditorOption.SaveItem = true; return fieldeditorOption.ToUrlString().ToString(); } private List<FieldDescriptor> CreateFieldDescriptors(string fields) { var fieldList = new List<FieldDescriptor>(); var fieldString = new ListString(fields); foreach (string field in new ListString(fieldString)) fieldList.Add(new FieldDescriptor(RequestContext.Item, field)); return fieldList; } public override PipelineProcessorResponseValue ProcessRequest() { return new PipelineProcessorResponseValue { Value = GenerateUrl() }; } } |
The LaunchFieldEditor.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
define(["sitecore"], function (Sitecore) { Sitecore.Commands.LaunchFieldEditor = { canExecute: function(context) { //YOU COULD ADD FUNCTIONALITY HERE TO SEE IF ITEMS HAVE THE CORRECT FIELDS return true; }, execute: function(context) { ///CHOOSE YOUR OPTION BELOW // THIS IS FOR THE ALT TEXT ON IMAGE //context.currentContext.argument = context.button.viewModel.$el[0].firstChild.alt; //THIS IS THE TOOLTIP ON LINK TAG "A" //context.currentContext.argument = context.button.viewModel.$el[0].title; // THIS IS THE ACCESS KEY context.currentContext.argument = context.button.viewModel.$el[0].accessKey; Sitecore.ExperienceEditor.PipelinesUtil.generateRequestProcessor("ExperienceEditor.GenerateFieldEditorUrl", function(response) { var DialogUrl = response.responseValue.value; var dialogFeatures = "dialogHeight: 680px;dialogWidth: 520px;"; Sitecore.ExperienceEditor.Dialogs.showModalDialog(DialogUrl, '', dialogFeatures, null); }).execute(context); } }; }); |
update: if you’re using 8.1 + then the js code needs to be modified slightly – feedback from Yoki in the comments (and tested in 8.2u1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
define([“sitecore”, “/-/speak/v1/ExperienceEditor/ExperienceEditor.js”], function (Sitecore, ExperienceEditor) { Sitecore.Commands.LaunchFieldEditor = { canExecute: function (context) { return true; }, execute: function (context) { context.currentContext.argument = context.button.viewModel.$el[0].accessKey; ExperienceEditor.PipelinesUtil.generateRequestProcessor(“ExperienceEditor.GenerateFieldEditorUrl”, function (response) { var DialogUrl = response.responseValue.value; var dialogFeatures = “dialogHeight: 680px;dialogWidth: 520px;”; ExperienceEditor.Dialogs.showModalDialog(DialogUrl, ”, dialogFeatures, null); }).execute(context); } }; }); |
After all have been setup correctly the content author can now edit the meta data button through the experience editor.
go to sitecore->client->applications->webedit->ribbons->webedit
should be:
go to sitecore->content->applications->webedit->ribbons->webedit
Thanks Sander,
I’ve updated the post
Update Sitecore 8.1 for javascript:
ExperienceEditor are no longer part of Sitecore. ExperienceEditor require to be defined implicitly to avoid of undefined Sitecore.ExperienceEditor.
Below the code update:
define([“sitecore”, “/-/speak/v1/ExperienceEditor/ExperienceEditor.js”], function (Sitecore, ExperienceEditor) {
Sitecore.Commands.LaunchFieldEditor =
{
canExecute: function (context) {
return true;
},
execute: function (context) {
context.currentContext.argument = context.button.viewModel.$el[0].accessKey;
ExperienceEditor.PipelinesUtil.generateRequestProcessor(“ExperienceEditor.GenerateFieldEditorUrl”, function (response) {
var DialogUrl = response.responseValue.value;
var dialogFeatures = “dialogHeight: 680px;dialogWidth: 520px;”;
ExperienceEditor.Dialogs.showModalDialog(DialogUrl, ”, dialogFeatures, null);
}).execute(context);
}
};
});
thanks for the update Yoki!
Hi Rahadian,
I was tried with above code.but i am getting the issue in jquery. it shows the error “Uncaught TypeError: Cannot read property ‘generateRequestProcessor’ of undefined”.how to resolve this issue?
Which Sitecore version are you using? this post was based on 8.0 release, the recent update for 8.1 have a slightly different approach for the LaunchFieldEditor.js
I recently tried to implement this on 8.2u1 release using the js code update and it’s working fine
Hi,
I am Using sitecore 8.1 upgrade3.
Hi Radhian,
I tried everything what you mentioned in the article.I checked the log files also.it shows “Could not instantiate speak request object”.I am using sitecore 8.1 upgrade 3,Visual studio 2015 professional.please let me know how to resolve this issue?
please respond As soon As Possible.
Thanks in Advance
What does it even means
“In Sitecore Rocks select tasks and design layout then add a new rendering of type Strip”
?
I meant add new rendering with template of Strip
Update for Sitecore 9 ( for me At least ) :
define([“sitecore”, “/-/speak/v1/ExperienceEditor/ExperienceEditor.js”], function (Sitecore, ExperienceEditor) {
Sitecore.Commands = Sitecore.Commands || {};
Sitecore.Commands.LaunchFieldEditor =
{
canExecute: function (context) {
//YOU COULD ADD FUNCTIONALITY HERE TO SEE IF ITEMS HAVE THE CORRECT FIELDS
return true;
},
execute: function (context) {
///CHOOSE YOUR OPTION BELOW
// THIS IS FOR THE ALT TEXT ON IMAGE
//context.currentContext.argument = context.button.viewModel.$el[0].firstChild.alt;
//THIS IS THE TOOLTIP ON LINK TAG “A”
//context.currentContext.argument = context.button.viewModel.$el[0].title;
// THIS IS THE ACCESS KEY
context.currentContext.argument = context.button.viewModel.$el[0].accessKey;
ExperienceEditor.PipelinesUtil.generateRequestProcessor(“Custom.GenerateFieldEditorUrl”, function (response) {
var DialogUrl = response.responseValue.value;
var dialogFeatures = “dialogHeight: 680px;dialogWidth: 520px;”;
ExperienceEditor.Dialogs.showModalDialog(DialogUrl, ”, dialogFeatures, null);
}).execute(context);
}
};
});
Hi, I am having trouble with getting this implemented in sitecore 9. Not able to find reference to “PipelineProcessorRequest” . Does anyone know the assembly ?