Skip to content

Instantly share code, notes, and snippets.

@moo2u2
Last active May 5, 2016 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moo2u2/fd2963d4964d5b3e586a7c598f39dd5a to your computer and use it in GitHub Desktop.
Save moo2u2/fd2963d4964d5b3e586a7c598f39dd5a to your computer and use it in GitHub Desktop.
namespace Site.Common
{
using System.Collections.Generic;
using Sitecore.Data;
using Sitecore.Data.Items;
public class CreateNonEditableSnippet
{
// The dictionary keys that are passed to the ExecuteTask method
public const string TaskId = "ItemID";
public const string Language = "LanguageIndex";
public const string CurrentUser = "CurrentUserName";
public const string ProjectItem = "ci_projectPanel";
public const string ContentItem = "ci_contentBrowser";
public const string LibraryItem = "ci_libraryBrowser";
public const string ImageItem = "ci_imageViewer";
public const string WorkboxItem = "ci_workBox";
// Relevant template IDs
public static readonly ID PageId = new ID("{6BFA47BA-F73C-48DB-9170-C0CC94179EC7}");
public static readonly TemplateID CustomSnippetId = new TemplateID(new ID("{C0FD5401-A2A5-4205-831D-DF06120B389E}"));
public string ExecuteTask(Dictionary<string, object> dictionary)
{
Item page = Sitecore.Context.Database.GetItem(new ID(dictionary[ProjectItem].ToString()));
if (page.TemplateID != PageId)
{
return "Please select a page under which to add the non-editable snippet";
}
page.Add("Non-Editable", CustomSnippetId);
return $"Created custom snippet under page {page.Name}.";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment