Skip to content

Instantly share code, notes, and snippets.

@moo2u2 moo2u2/CreateNonEditableSnippet.cs Secret
Last active May 5, 2016

What would you like to do?
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
You can’t perform that action at this time.