-
-
Save moo2u2/fd2963d4964d5b3e586a7c598f39dd5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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