1

I am trying to add a shortcut to Content Editor in Workbox ribbon.

enter image description here

I can't figure out what template it will be either a panel or a button, if panel then what data type.

Would be great if someone can guide me in the right direction. Thanks

  • When you say "Content Editor". Like just go to the whole content editor. Or open a specific workbox item in the content editor? – Chris Auer May 19 '17 at 22:02
  • Yeah just a shortcut to take a user to Content Editor – jahan May 20 '17 at 4:50
5

It all depends on your requirement.

When to use the Panel

Using the panel, it will act as a container where you can add labels, button and so on via code. Let's take the example for the Page Size. The page size is a panel and in the code-behind you will see that Sitecore actually build the label Items per page and the combo box for the number of items. See below screenshot of the code snippet from the namespace Sitecore.Shell.Applications.Workbox.PageSizePanel,Sitecore.Client.

enter image description here

For your case, I think you can directly create a button based on the template /sitecore/templates/System/Ribbon/Small Button and then add the method for the command in the Click Field.

Implementation

Create an item in the Core database using the /sitecore/templates/System/Ribbon/Small Button template.

Then, in the Click Field, add a command. For example: contenteditor:open.

Now, the code. Create a new class which extends the Sitecore.Shell.Framework.Commands.Command and add the required code. A snippet is shown below:

public class ContentEditor : Command
{
    public override void Execute(CommandContext context)
    {
        // Any additional logic goes here.

        // Create a new UrlString to pass the different querystrings.
        UrlString str = new UrlString(); 

        // The querystring id and fo should have an item id.
        // You may set them to the Home item id.
        str.Add("id", "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}");
        str.Add("fo", "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}");

        // This will generate the url for the Content Editor with the different querystrings.
        Windows.RunApplication("Content editor", str.ToString());
    }
}

You need to add a patch for the command to run. This is shown below:

<configuration  xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <commands>
      <command name="contenteditor:open" type="YourNamespaceWithClassName,YourAssemblyName"/>
    </commands>    
  </sitecore>
</configuration>

Note: If you decide not to use the contenteditor:open but another one, make sure to change it also in the config file.

| improve this answer | |
  • Yeah that makes sense. Will I need to write my own method to perform the button click i.e. redirect to content editor? – jahan May 20 '17 at 4:59
  • @jahan, please see updated answer – Hishaam Namooya May 20 '17 at 12:08
  • Thanks for the answer. Have tried it out and it works. Only issue is that it opens the content editor as a popup window rather then redirecting. – jahan May 22 '17 at 15:08
  • Tou can try to perform a url redirection instead of RunApplication – Hishaam Namooya May 22 '17 at 17:16
  • Tried redirect going to update it in answer below – jahan May 23 '17 at 11:41
1

Created a generic class to handle any shortcuts:

class ApplicationShortcuts : Command
{
    public override void Execute(CommandContext context)
    {
        if (!string.IsNullOrEmpty(context.Parameters["url"]))
        {
            // Redirect to URL
            SheerResponse.Eval("window.parent.location.href ='"+context.Parameters["url"]+ "';");
        }
    }
}

Passing in the URL as a parameter. Makes it easy to change the URL if needed through editor and flexibility to create more shortcuts.

| improve this answer | |

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.