Skip to content

Instantly share code, notes, and snippets.

View blacktambourine's full-sized avatar

Black Tambourine blacktambourine

View GitHub Profile
@blacktambourine
blacktambourine / PageEvents.cs
Created March 10, 2017 09:19
Sitecore Page Events to add Search Terms to Analytics
using Sitecore.Analytics;
using Sitecore.Analytics.Data;
using Sitecore.Analytics.Tracking;
using Sitecore.Data;
namespace BlackTambourine.Core.Sitecore.Helpers
{
public class PageEvents
{
public static ID PageEventSearchId { get { return new ID("{0C179613-2073-41AB-992E-027D03D523BF}"); } }
@blacktambourine
blacktambourine / RenderingDatasourceHelperUsage.cs
Last active August 22, 2017 08:43
RenderingDatasourceHelper Usage
public void Example()
{
//Get the personalised datasource of the "Call To Action" rendering in the "cta" placeholder of this particular "Landing Page" content item.
var landingPageItem = Sitecore.Context.Database.GetItem(landingPageId);
var renderingId = new ID("{3590F496-6D5F-4376-976D-208FCEFC15F3}"); //"Call To Action" View Renderings only
var placeHolderName = "cta";
var itemList = GetPersonalisedPlaceHolderDatasourceItems(Sitecore.Context.Device, landingPageItem, placeHolderName, renderingId);
@blacktambourine
blacktambourine / RenderingDatasourceHelper.cs
Last active August 22, 2017 08:34
Get Personalised Datasource from a View Rendering
using System;
using System.Collections.Generic;
using System.Linq;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Layouts;
using Sitecore.Rules;
using Sitecore.Rules.ConditionalRenderings;
namespace BlackTambourine.Core.Sitecore.Helpers
@blacktambourine
blacktambourine / NoDatasourceSafeViewRenderer.cs
Created February 1, 2017 07:23
Handle missing Datasource with GlassView
using System;
using Sitecore.Mvc.Presentation;
namespace Diversus.Core.Sitecore.ViewRenderers
{
/// <summary>
/// GlassView ViewRenderings require a datasource, gracefully handle when they do not (i.e. Sitecore will try to pass in a RenderingModel when no model is found).
/// Handles the error: "The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type XXXX"
/// </summary>
public class NoDatasourceSafeViewRenderer : ViewRenderer
@blacktambourine
blacktambourine / ExceptionSafeViewRenderer.cs
Created February 1, 2017 07:22
Handle Exceptions with GlassView
using System;
using Sitecore.Diagnostics;
using Sitecore.Mvc.Presentation;
namespace Diversus.Core.Sitecore.ViewRenderers
{
public class ExceptionSafeViewRenderer : ViewRenderer
{
/// <summary>
/// Handle any Exceptions in the mvc rendering. Also handles missing datasources.
@blacktambourine
blacktambourine / GetViewRendererWithItemValidation.cs
Created February 1, 2017 07:21
Handle errors and missing datasource in GlassViews
using Diversus.Core.Sitecore.ViewRenderers;
using Sitecore.Mvc.Extensions;
using Sitecore.Mvc.Pipelines.Response.GetRenderer;
using Sitecore.Mvc.Presentation;
namespace Diversus.Core.Sitecore.Pipeline
{
public class GetViewRendererWithItemValidation : GetViewRenderer
{
/// <summary>
@blacktambourine
blacktambourine / solrconfig.xml
Created December 21, 2016 01:57
Sitecore Azure Solr config file for Sitecore 8.2 Update 1
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@blacktambourine
blacktambourine / Sitecore.Azure.Setup.config
Created August 18, 2016 02:46
Sitecore Azure Setup Patch Config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<sc.variable name="dataFolder" set:value="/App_Data" />
<!--<pipelines>
<initialize>
<processor type="Sitecore.Azure.Startup.Pipelines.Loader.RebuildSearchIndex, Sitecore.Azure.Startup" patch:after="processor[@type='Sitecore.Pipelines.Loader.EnsureAnonymousUsers, Sitecore.Kernel']" />
</initialize>
</pipelines>-->
@blacktambourine
blacktambourine / waiting to receive data.sql
Created June 23, 2016 02:33
SQL Statements need to rebuild Sitecore Analytics Reporting SQL Database
/****** Analytics Rebuild "waiting to receive data" Step ******/
INSERT INTO
[Sitecore_AnalyticsSecondary].[dbo].[CampaignActivityDefinitions]
SELECT * FROM [Sitecore_Analytics].[dbo].[CampaignActivityDefinitions]
INSERT INTO
[Sitecore_AnalyticsSecondary].[dbo].GoalDefinitions
SELECT * FROM [Sitecore_Analytics].[dbo].GoalDefinitions
INSERT INTO
@blacktambourine
blacktambourine / schema.xml
Created June 14, 2016 02:07
SOLR schema.xml post Sitecore generation (Sitecore 8.1 Update 3 and SOLR 5.5)
<?xml version="1.0" encoding="utf-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0