Skip to content

Instantly share code, notes, and snippets.

@BillCacy
BillCacy / Replace-ReferencedRendering-Header.ps1
Created December 2, 2021 01:33
Sitecore Powershell Script to replace existing rendering with a new rendering
Set-Location master:
function Get-ItemBasedOnTemplate {
param(
[string]$TemplateId
)
$queue = New-Object System.Collections.Queue
$processedLookup = New-Object System.Collections.Generic.HashSet[string]
if(-not(Test-Path -Path "master:$($TemplateId)")) { return }
@BillCacy
BillCacy / ProcessQueryStringCampaign.xml
Created October 20, 2020 22:58
Patch file for overriding the Sitecore.Analytics.Pipelines.StartTracking.ProcessQueryStringCampaign
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore role:require="Standalone or ContentDelivery or ContentManagement">
<pipelines>
<startTracking>
<!-- Patched to handle instances where campaign is expired but can still be triggered -->
<processor type="Sitecore.Analytics.Pipelines.StartTracking.ProcessQueryStringCampaign, Sitecore.Analytics">
<patch:attribute name="type">YOURNAMESPACE.Analytics.Pipelines.StartTracking.ProcessQueryStringCampaignEx, YOURNAMESPACE.Analytics</patch:attribute>
</processor>
</startTracking>
</pipelines>
@BillCacy
BillCacy / ProcessQueryStringCampaignEx.cs
Last active October 20, 2020 22:33
Override of Sitecore.Analytics.Pipelines.StartTracking.ProcessQueryStringCampaign to prevent campaign triggering when the end date has passed.
using System;
using Sitecore.Abstractions;
using Sitecore.Analytics.Pipelines.StartTracking;
using Sitecore.Data;
namespace YOURNAMESPACE.Analytics.Pipelines.StartTracking
{
public class ProcessQueryStringCampaignEx : ProcessQueryStringCampaign
{
public ProcessQueryStringCampaignEx() : base() { }
@BillCacy
BillCacy / SaveDataWithEncryption.cs
Last active July 31, 2020 06:15
Sitecore 9 Forms Encrypted Field Save Action
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Sample.Foundation.Core.Helpers;
using Sitecore.Diagnostics;
using Sitecore.ExperienceForms.Data;
using Sitecore.ExperienceForms.Data.Entities;
using Sitecore.ExperienceForms.Models;
using Sitecore.ExperienceForms.Processing;
@BillCacy
BillCacy / SingleLineTextEncrypted.cshtml
Created July 31, 2020 05:52
Sitecore 9 Forms Encrypted text field view
@using Sitecore.ExperienceForms.Mvc.Html
@model Sample.Feature.Forms.ViewModels.StringInputEncryptedViewModel
<label for="@Html.IdFor(m => Model.Value)" class="@Model.LabelCssClass">@Html.DisplayTextFor(t => Model.Title)</label>
<input id="@Html.IdFor(m => Model.Value)" name="@Html.NameFor(m => Model.Value)" class="@Model.CssClass" type="text" value="@Model.Value" @if (Model.MaxLength > 0) { <text> maxlength="@Model.MaxLength" </text> } placeholder="@Model.PlaceholderText" data-sc-tracking="@Model.IsTrackingEnabled" data-sc-field-name="@Model.Name" data-sc-field-key="@Model.ConditionSettings.FieldKey" @Html.GenerateUnobtrusiveValidationAttributes(m => m.Value) />
@Html.ValidationMessageFor(m => Model.Value)
@BillCacy
BillCacy / StringInputEncryptedViewModel.cs
Created July 31, 2020 05:39
Sitecore 9 Forms Encrypted Field View Model
using System;
using Sitecore.ExperienceForms.Mvc.Models.Fields;
namespace Sample.Feature.Forms.ViewModels
{
[Serializable]
public class StringInputEncryptedViewModel : StringInputViewModel
{
}
}
@BillCacy
BillCacy / FindAllItemsByTemplateWithValueInField.ps1
Created May 22, 2020 19:33
Looks for all items with specified template name that have a value in the specified field
$root = gi master:// -id "{C557F52C-BDBA-4F3D-BAD0-E315AD39C9CB}"
$items = $root | ls -r | ?{$_.TemplateName -eq "<TEMPLATE NAME>"}
$fieldName = "<FIELD NAME>"
foreach($i in $items){
if(-not([string]::IsNullOrWhitespace($i.Fields[$fieldName]))){
$i.Name + " : " + $i.Fields[$fieldName].Value + " : " + $i.Paths.FullPath
}
}
@BillCacy
BillCacy / LocalSettings.psm1
Created October 10, 2018 04:28
Mapping of Solr settings using user-defined values. This is used for local testing to simulate the process Octopus will use.
using module ".\BlueGreenSolrSettings.psm1"
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
<#
.SYNOPSIS
Creates a BlueGreenSolrSettings object with property values defined by the user
#>
function Get-LocalBlueGreenSolrSettings()
@BillCacy
BillCacy / BlueGreenSolr-Local.ps1
Created October 10, 2018 04:27
Script to utilize in local testing of the Solr functionality pieces of a blue/green deployment. This utilizes the LocalSettings.psm1 file that maps user-defined values to the Solr settings.
using module ".\BlueGreenSolrSettings.psm1"
using module ".\LocalSettings.psm1"
<#
.SYNOPSIS
Calls the Solr functions for SolrCloud CDCR to test in a non-live environment (without Octopus deploy).
The .\LocalSettings.psm1 file is used to map user-defined variable values to
the .\BlueGreenSolrSettings.psm1 properties.
.PARAMETER startingReplication
@BillCacy
BillCacy / BlueGreenSolr.ps1
Created October 10, 2018 04:25
Script to call the Solr functionality from an Octopus step.
using module ".\BlueGreenSolrSettings.psm1"
using module ".\BlueGreenSolrSettingsMap.psm1"
<#
.SYNOPSIS
Calls the Solr functions for SolrCloud CDCR to update a Live environment (with Octopus deploy).
The .\BlueGreenSolrSettingsMap.psm1 file is used to map Octopus-defined variable values to
the .\BlueGreenSolrSettings.psm1 properties.
.PARAMETER startingReplication