Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamie Pollock jamiepollock

View GitHub Profile
@jamiepollock
jamiepollock / ProtectConfiguredError404PagesComponent.cs
Last active Feb 7, 2020
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
jamiepollock / PreRequestScript.js
Created Sep 5, 2018
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
jamiepollock / eu_cookie_banner.js
Created Mar 19, 2018 — forked from bavington/eu_cookie_banner.js
Simple EU Cookie Law Banner JavaScript
View eu_cookie_banner.js
@jamiepollock
jamiepollock / CustomMigrationBase.cs
Last active Jan 22, 2018
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
jamiepollock / Bootstrap3.cshtml
Created Apr 16, 2017
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
jamiepollock / MyController.cs
Last active Oct 8, 2019
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
jamiepollock / DecimalTests.cs
Created Feb 1, 2017
Tests for Decimal conversion in Umbraco Ditto
View DecimalTests.cs
using NUnit.Framework;
using Our.Umbraco.Ditto.Tests.Mocks;
namespace Our.Umbraco.Ditto.Tests
{
[TestFixture]
[Category("Processors")]
public class DecimalTests
{
public class MyModel
@jamiepollock
jamiepollock / FormHtmlApiController.cs
Created Jan 26, 2017
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
jamiepollock / LocalizedEditorModelEventManagerEventHandler.cs
Created Oct 21, 2016
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
jamiepollock / AddCustomPropertyToBeAddedLaterToMyPocoTable.cs
Last active May 15, 2018
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