Skip to content

Instantly share code, notes, and snippets.

View MartinMiles's full-sized avatar

Martin Miles MartinMiles

View GitHub Profile
@MartinMiles
MartinMiles / Rebind-TopLevelPlaceholders.ps1
Last active June 15, 2025 08:41
Processes all the rendering for a page and rebinds a top level component from one to another (say, from `page-layout` to `headless-main`) including those nested
# -----------------------------------------------------------
# Inline Script for Sitecore PowerShell ISE:
# Replace Multiple Placeholders for Renderings
# Target Item: Default is /sitecore/content/Zont/Habitat/Home/AAA
# DB: master
# - Processes Standard Values, Shared Layout, and Final Layout.
# - Replaces three placeholder pairs:
# $OldPlaceholder1 → $NewPlaceholder1
# $OldPlaceholder2 → $NewPlaceholder2
# $OldPlaceholder3 → $NewPlaceholder3
@MartinMiles
MartinMiles / Set-LayoutItemForPagePresentation.ps1
Last active June 3, 2025 06:59
Sets Layout item for the page's presentation details (on a shared layout field) without modifying/resetting the rest of presentation/renderings
param(
[string]$PageItemPath = "/sitecore/content/Zont/Habitat/Home/AAA",
[string]$LayoutItemPath = "/sitecore/layout/Layouts/Foundation/JSS Experience Accelerator/Presentation/JSS Layout"
)
# 1. Mount "master:" drive if missing
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
try {
New-PSDrive -Name master -PSProvider Sitecore -Root "/" -Database "master" -ErrorAction Stop | Out-Null
Write-Host "📁 Mounted master: drive."
# Batch Create / Update Rendering Definitions for Zont Feature
# ------------------------------------------------------------
# ❶ Mount master: drive if absent
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
New-PSDrive -Name master -PSProvider Sitecore -Root "/" -Database "master" -ErrorAction Stop | Out-Null
}
# ❷ Grab master DB and base item
$db = [Sitecore.Configuration.Factory]::GetDatabase("master")
$basePath = "/sitecore/layout/Renderings"
@MartinMiles
MartinMiles / Show-LargestMediaItems.ps1
Created May 30, 2025 19:07
Shows all the media sorted by the size, descending, from the largest to the smallest
# It will show all the media sorted by the size, descending, from the largest to the smallest
# 1) Mount master: PSDrive if it’s not present
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
New-PSDrive -Name master -PSProvider Sitecore -Root "\" -Database master | Out-Null
}
# 2) Cache the master database object
$database = [Sitecore.Configuration.Factory]::GetDatabase("master")
# Creates rendering definition item under a specified ID, in this case it is: {781C6B36-4B02-46EA-8ADC-B92A11877F10}
# 1. Define the full path for the rendering
$FullPath = "/sitecore/layout/Renderings/Feature/Zont/Teasers/Content Teaser with Summary"
# 2. Mount the master: PSDrive if it’s not already mounted
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
New-PSDrive -Name master -PSProvider Sitecore -Root "/" -Database "master" -ErrorAction Stop | Out-Null
}
-- We attach two legacy databases into a locally-run XM Cloud instance: "CoreOld" and "Old" (which is master)
EXEC sys.sp_configure N'contained database authentication', N'1'
go
exec ('RECONFIGURE WITH OVERRIDE')
go
CREATE DATABASE [Sitecore.Old]
ON (FILENAME = 'C:\data\Sitecore.Old_Primary.mdf'),
(FILENAME = 'C:\data\Sitecore.Old_Primary.ldf')
# Moves page items in bulk preserving the IDs (here's one level up, but could be anything, but did not work between databases):
param(
[string]$SourceDatabase = "master",
[string]$SourcePath = "sitecore/content/Zont/Habitat/Home/Home",
[string]$DestinationDatabase = "master",
[string]$DestinationPath = "sitecore/content/Zont/Habitat/Home"
)
# 1. Ensure both PS drives exist
@MartinMiles
MartinMiles / SPE.Remoting.Permissions.config
Last active June 18, 2025 10:01
Three configs to enable SPE & Remoting on XM Cloud (requires `SPE_REMOTING_SECRET` set in the .env file). Put these three files under `App_Config/Include/zzz` folder
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<httpRequestBegin>
<!--
We replace the existing RequireAuthentication processor (to preserve all its attributes)
and add our IgnoreRules list underneath.
-->
<processor
@MartinMiles
MartinMiles / Get-AllRenderingDefinitions-WITH-SITE-SPECIFIC-DATASOURCES.sql
Last active June 15, 2025 11:38
Gets the layout for the entire non-SXA website (tested on an example of Habitat with Sitecore 9.2)
--- PAY ATTENTION TO THE BELOW LINE !!!
use [Sitecore.Old]
GO
--------------------------------------------------------------------------------
-- 0) Identify layout‐field IDs
--------------------------------------------------------------------------------
DECLARE
@SharedLayoutFieldId UNIQUEIDENTIFIER,
@MartinMiles
MartinMiles / Sitemap.aspx
Last active May 3, 2025 16:21
Admin folder tool for XM Cloud to regenerate the sitemap media library item in a development environment + sitemap generation at Next.js
<%@ Page language="c#" %>
<%@ Import Namespace="Microsoft.Extensions.DependencyInjection" %>
<%@ Import Namespace="Sitecore.Abstractions" %>
<%@ Import Namespace="Sitecore.Configuration" %>
<%@ Import Namespace="Sitecore.Data" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="Sitecore.DependencyInjection" %>
<%@ Import Namespace="Sitecore.Events" %>
<%@ Import Namespace="Sitecore.Globalization" %>
<%@ Import Namespace="Sitecore.Pipelines" %>