Skip to content

Instantly share code, notes, and snippets.

View jamiepollock's full-sized avatar

Jamie Pollock jamiepollock

View GitHub Profile
jamiepollock / ProtectConfiguredError404PagesComponent.cs
Last active February 7, 2020 07:37
An Umbraco 8 component/composer for protecting pages that are configured as 404 pages in umbracoSettings.config.
View ProtectConfiguredError404PagesComponent.cs
namespace MyApplication.Components
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Events;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Services.Implement;
jamiepollock / PreRequestScript.js
Created September 5, 2018 15:16
Postman JS Pre-request script for dynamic dates.
View PreRequestScript.js
var moment = require('moment');
// Allows dates to be offset in the past rather than right now. offset format "hh:mm:ss".
// "24:00:00" would be 24hrs in the past.
var offsetValue = pm.globals.get("offset");
var offset = moment.duration(offsetValue);
// Determines the duration between start & end dates format "hh:mm:ss"
// "00:30:00" would be a 30 minute delay.
var durationValue = pm.globals.get("duration");
jamiepollock / eu_cookie_banner.js
Created March 19, 2018 19:56 — forked from bavington/eu_cookie_banner.js
Simple EU Cookie Law Banner JavaScript
View eu_cookie_banner.js
jamiepollock / CustomMigrationBase.cs
Last active January 22, 2018 16:49
A layer on top of Umbraco's MigrationBase for checking a table has Indexes, Constraints & Columns
View CustomMigrationBase.cs
using System.Linq;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.Migrations;
using Umbraco.Core.Persistence.SqlSyntax;
namespace My.Website.Migrations
public abstract class CustomMigrationBase : MigrationBase
public CustomMigrationBase(ISqlSyntaxProvider sqlSyntax, ILogger logger) : base(sqlSyntax, logger)
jamiepollock / Bootstrap3.cshtml
Created April 16, 2017 00:35
Example of Umbraco GridSettings using the Bootstrap3.cshtml with Umbraco v7.5.4+
View Bootstrap3.cshtml
@inherits UmbracoViewPage<dynamic>
@using Umbraco.Web.Templates;
@using Newtonsoft.Json.Linq;
@using Our.Umbraco.GridSettings.Web;
@using Our.Umbraco.GridSettings.Services;
@using Our.Umbraco.GridSettings.Resolvers;
var attributesResolver = new GroupByPrefixTokenGridSettingsAttributesResolver("_");
var attributesService = new GridSettingsAttributesService(attributesResolver);
jamiepollock / MyController.cs
Last active October 8, 2019 15:27
Umbraco XPath query with tokens
View MyController.cs
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco.Web;
using Umbraco.Core.Xml;
using Umbraco.Web.Mvc;
namespace MyWebsite.Controllers
public class MyController : RenderMvcController
jamiepollock / DecimalTests.cs
Created February 1, 2017 04:03
Tests for Decimal conversion in Umbraco Ditto
View DecimalTests.cs
using NUnit.Framework;
using Our.Umbraco.Ditto.Tests.Mocks;
namespace Our.Umbraco.Ditto.Tests
public class DecimalTests
public class MyModel
jamiepollock / FormHtmlApiController.cs
Created January 26, 2017 19:12
In Theory (TM)! How to return an Umbraco Form HTML from an ApiController
View FormHtmlApiController.cs
using System.Web;
using Umbraco.Web.WebApi;
namespace My.Website.Controllers.Api
public class FormHtmlApiController : UmbracoApiController
public IHtmlString Get(string id)
return Umbraco.RenderMacro("FormsRenderForm", new { FormGuid = id });
jamiepollock / LocalizedEditorModelEventManagerEventHandler.cs
Created October 21, 2016 16:30
Working with EditorModelEventManager to localise an EditorContentModel powered by /config/lang/*.user.xml files
View LocalizedEditorModelEventManagerEventHandler.cs
using System.Collections.Generic;
using System.Globalization;
using Umbraco.Core;
using Umbraco.Core.Services;
using Umbraco.Web;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
namespace MyWebsite
jamiepollock / AddCustomPropertyToBeAddedLaterToMyPocoTable.cs
Last active May 15, 2018 23:57
Code to represent using custom Umbraco Migrations with Umbraco v7.3.0
View AddCustomPropertyToBeAddedLaterToMyPocoTable.cs
using System;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Migrations;
using Umbraco.Core.Persistence.SqlSyntax;
namespace MyApp.Migrations
[Migration("1.1.0", 1, MyCustomSectionMigrationConstants.ProductName)]
public class AddCustomPropertyToBeAddedLaterToMyPocoTable : MigrationBase