Skip to content

Instantly share code, notes, and snippets.

@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: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 / 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 / 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);
}