The following covers how to add a new button to the Sitecore ribbon.
The following Sitecore changes must be done in the core database.
/sitecore/content/Applications/Content Editor/Ribbons/Chunks/*group name*
-
Template: /sitecore/templates/System/Ribbon/Chunk
-
Populate Header and ID fields.
/sitecore/content/Applications/Content Editor/Ribbons/Chunks/group name/button name
-
Template: /sitecore/templates/System/Ribbon/Large Button
-
Populate Header, Icon, Click, and Tooltip fields.
/sitecore/content/Applications/Content Editor/Ribbons/Strips/*tab name*
-
Template: /sitecore/templates/System/Ribbon/Strip
-
Populate Header, ID, and Access Key fields.
/sitecore/content/Applications/Content Editor/Ribbons/Strips/tab name/section name
-
Template: /sitecore/templates/System/Reference
-
Populate Reference field (point to Chunk, such as
sitecore/content/Applications/Content Editor/Ribbons/Chunks/*group name*
)
/sitecore/content/Applications/Content Editor/Ribbons/Ribbons/Default/*tab name*
- Template: /sitecore/templates/System/Reference
- Populate Reference field (point to Strip, such as
sitecore/content/Applications/Content Editor/Ribbons/Strips/*tab name*
)
- Should be placed within App_Config\Include inside the Sitecore CMS project.
- Example config:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<!-- Domain to load when previewing pages. Include the protocol but not the trailing slash. -->
<setting name="Wsob.SitecoreCms.Commands.ViewOnPreviewCommand.PreviewDomain" value="http://example.com" />
</settings>
<commands>
<command name="wsb:viewonpreview" type="Wsob.SitecoreCms.Commands.ViewOnPreviewCommand, Wsob.SitecoreCms" />
</commands>
</sitecore>
</configuration>
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Shell.Framework.Commands;
using System;
namespace Wsob.SitecoreCms.Commands
{
internal class ViewOnPreviewCommand : Command
{
public override void Execute(CommandContext context)
{
if (context != null && context.Items.Length == 1)
{
Item contextItem = context.Items[0];
if (contextItem.Visualization.Layout != null)
{
openNewWindow(contextItem);
}
else
{
Log.Info("[WSB Preview] Failed previewing item " + contextItem.ID, this);
Sitecore.Context.ClientPage.ClientResponse.Alert("Currently only pages can be previewed. Please select a page with layout.");
}
}
}
private void openNewWindow(Item item)
{
var urlOptions = new Sitecore.Links.UrlOptions();
urlOptions.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Never;
urlOptions.LowercaseUrls = true;
var previewDomain = Sitecore.Configuration.Settings.GetSetting("Wsob.SitecoreCms.Commands.ViewOnPreviewCommand.PreviewDomain");
if (string.IsNullOrWhiteSpace(previewDomain))
{
previewDomain = "http://example.com";
}
var currentSite = Sitecore.Context.GetSiteName();
Sitecore.Context.SetActiveSite("bus");
var itemUrl = Sitecore.Links.LinkManager.GetItemUrl(item, urlOptions);
Sitecore.Context.SetActiveSite(currentSite);
Log.Info("[WSB Preview] Item url: " + itemUrl, this);
itemUrl = previewDomain + itemUrl;
Sitecore.Context.ClientPage.ClientResponse.Eval(string.Format("window.open('{0}');", itemUrl));
}
}
}