Skip to content

Instantly share code, notes, and snippets.

View siteContextSwitcher.cs
SiteContext targetSiteContext = SiteContext.GetSite(sitename);
using (var context = new SiteContextSwitcher(targetSiteContext))
{
// do something on the new site context
Item myItem = context.Database.GetItem("ID");
}
View TemplateItemExtensions.cs
public static class TemplateItemExtensions
{
public static IEnumerable<TemplateFieldItem> GetFieldsOfSelfAndBaseTemplates(this TemplateItem self)
{
var templateFieldItems = new Dictionary<ID, TemplateFieldItem>();
GetAllFieldsForTemplate(self, templateFieldItems);
return templateFieldItems.Values;
}
View SingleLineTextWithPlaceholderField.cs
using Sitecore.Form.Core.Attributes;
using System;
using System.ComponentModel;
using System.Web.UI;
namespace CustomWFFM.CustomFieldTypes
{
[ValidationProperty("Text")]
public class SingleLineTextWithPlaceholderField : Sitecore.Form.Web.UI.Controls.SingleLineText
{
View GetFieldsIncludingBase.cs
Template template = TemplateManager.GetTemplate(new ID(""), Sitecore.Context.Database);
TemplateField[] allFields = template.GetFields(true);
View QueryTokenReplacer.cs
using System;
using System.Text.RegularExpressions;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Pipelines.ExpandInitialFieldValue;
namespace CustomExpandTokenProcessors.Pipelines
{
public class QueryTokenReplacer : ExpandInitialFieldValueProcessor
{
View SingleLineTextWithPlaceholderFieldMvc.cs
using System.ComponentModel;
using Sitecore.Data.Items;
namespace CustomWFFM.CustomFieldTypes.Mvc
{
public class SingleLineTextWithPlaceholderField : Sitecore.Forms.Mvc.Models.Fields.SingleLineTextField
{
[DefaultValue("")]
public string PlaceholderText { get; set; }
View SingleLineTextWithPlaceholderField.cshtml
@using Sitecore.Mvc
@model CustomWFFM.CustomFieldTypes.Mvc.SingleLineTextWithPlaceholderField
@if (!Model.Visible)
{
return;
}
<div class="@Model.CssClass field-border">
View NextSortOrderReplacer.cs
using System.Linq;
using Sitecore.Configuration;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Pipelines.ExpandInitialFieldValue;
namespace CustomExpandTokenProcessors.Pipelines
{
public class NextSortOrderReplacer : ExpandInitialFieldValueProcessor
{
View CustomExpandTokenProcessorConfig.xml
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<expandInitialFieldValue>
<processor type="CustomExpandTokenProcessors.Pipelines.MyCustomTokenReplacer, CustomExpandTokenProcessors" patch:after="processor[@type='type=Sitecore.Pipelines.ExpandInitialFieldValue.ReplaceVariables, Sitecore.Kernel']"/>
</expandInitialFieldValue>
</pipelines>
</sitecore>
</configuration>
View CustomExpandTokenProcessorExample.cs
using Sitecore.Diagnostics;
using Sitecore.Pipelines.ExpandInitialFieldValue;
namespace CustomExpandTokenProcessors.Pipelines
{
public class CustomTokenReplacer : ExpandInitialFieldValueProcessor
{
private const string Token = "$customtoken";
public override void Process(ExpandInitialFieldValueArgs args)