Skip to content

Instantly share code, notes, and snippets.

@jbreuer
jbreuer / HomeUrlProvider
Last active August 29, 2015 14:04
Give the home node the parent url.
public class HomeUrlProvider : DefaultUrlProvider
{
public override string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
{
var content = umbracoContext.ContentCache.GetById(id);
if (content.DocumentTypeAlias == "Home" && content.Parent != null)
{
return base.GetUrl(umbracoContext, content.Parent.Id, current, mode);
}
@jbreuer
jbreuer / GoogleMapsConverter
Created July 24, 2014 15:22
GoogleMapsConverter for Umbraco 7.1.5 or higher
public class GoogleMapsConverter : PropertyValueConverterBase, IPropertyValueConverterMeta
{
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
{
if(source != null && !string.IsNullOrWhiteSpace(source.ToString()))
{
var coordinates = source.ToString().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (coordinates.Length == 3)
{
return new GoogleMaps
@jbreuer
jbreuer / gist:76d802851346b991af26
Created August 28, 2014 08:18
Nested Archetype. Doesn't seem to work.
var archetypeModel = this.GetPropertyValue<ArchetypeModel>("tourLocations");
return archetypeModel.Select(x =>
{
return new TourLocation()
{
Name = x.GetValue<string>("name"),
Translations = x.GetValue<ArchetypeModel>("translations").Select(y =>
{
return new Translation()
{
@jbreuer
jbreuer / gist:956aeb77c0c679f44cc0
Last active November 12, 2018 14:51
Get current domain root node in Umbraco content finder
public class NewsContentFinder : IContentFinder
{
public bool TryFindContent(PublishedContentRequest contentRequest)
{
if (contentRequest != null && contentRequest.HasDomain)
{
var rootDomainNode = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById(contentRequest.Domain.RootNodeId);
}
}
}
@jbreuer
jbreuer / gist:a396f1e4504e181e1c8a
Created November 20, 2014 10:51
Strongly typed querying in Umbraco
/// <summary>
/// Return the all the data required for filtering and displaying object types.
/// </summary>
/// <returns></returns>
public static IEnumerable<ObjectTypeItem> GetObjectTypeItems()
{
//Get the node where all projects and object types are below.
var projectOverview = Umbraco.TypedContent(ConfigurationManager.AppSettings["projectOverviewId"]);
return
@jbreuer
jbreuer / gist:0a5996e5e6bf881ce847
Last active December 31, 2018 05:24
Archetype and Nested Content as Models Builder properties
[ImplementPropertyType("slider")]
public IEnumerable<HomeSlider> Slider
{
get
{
var archetypeModel = this.GetPropertyValue<ArchetypeModel>("slider");
return archetypeModel.Select(x =>
{
return new HomeSlider()
{
@jbreuer
jbreuer / 0_reuse_code.js
Last active August 29, 2015 14:25
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jbreuer
jbreuer / gist:e4103c4d731fe3fdb275
Created July 16, 2015 12:53
Would be cool if this could work for Nested Content
var items = this.GetPropertyValue<IEnumerable<IPublishedContent>>("sliderNestedContent");
//Slider is a generated model based on a document type.
//Currently x as Slider returns null.
return items.Select(x => x as Slider);
@jbreuer
jbreuer / ContentExtensions.cs
Created May 18, 2016 14:59
An extension method to convert an IContent to an IPublishedContent.
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ContentExtensions.cs" company="Colours B.V.">
// © Colours B.V. 2015
// </copyright>
// <summary>
// The content extensions.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Project.Web.Core.Extensions
@jbreuer
jbreuer / HybridPlaceholder.jsx
Last active July 22, 2021 13:17
Hybrid Placeholder
import React, { useEffect, useState } from 'react';
import { withSitecoreContext, dataApi, Placeholder } from '@sitecore-jss/sitecore-jss-react';
import { dataFetcher } from './dataFetcher';
import config from './temp/config';
const HybridPlaceholder = ({
name,
rendering,
sitecoreContext,
}) => {