Skip to content

Instantly share code, notes, and snippets.

@sniffdk
sniffdk / gist:7412809
Created November 11, 2013 12:57
Demo code using InGroupsOf from Umbraco.Core.EnumerableExtensions
@using Umbraco.Core
@using uComponents.DataTypes.UrlPicker.Dto
@{
//var items = Model.resourceLinks.Items as List<UrlPickerState>;
var items = new List<UrlPickerState>
{
new UrlPickerState { Title = "Link1" },
new UrlPickerState { Title = "Link2" },
new UrlPickerState { Title = "Link3" },
new UrlPickerState { Title = "Link4" },
public class SearchTable : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
base.ApplicationStarted(umbracoApplication, applicationContext);
Umbraco.Core.Services.ContentService.Published += (sender, args) =>
{
foreach (var content in args.PublishedEntities)
{
@sniffdk
sniffdk / umbracoPage.Init
Last active December 21, 2015 00:59
Register a script oninit in /editcontent.aspx to allow for tab switching.
public class MyApplication : Umbraco.Web.UmbracoApplication
{
protected override void OnApplicationStarted(object sender, EventArgs e)
{
umbracoPage.Init += (p, args) =>
{
var page = p as umbracoPage;
if (page == null)
return;
var request = page.Page.Request;
@sniffdk
sniffdk / A custom Umbraco controller implementation
Last active December 20, 2015 12:59 — forked from mattbrailsford/ListingController.cs
A slightly modified version of custom controllers/views. Works perfectly on my machine :)
public class Global : UmbracoApplication
{
protected override void OnApplicationStarting(object sender, EventArgs e)
{
base.OnApplicationStarting(sender, e);
DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(ListingPageController));
}
}
@sniffdk
sniffdk / gist:5583994
Created May 15, 2013 13:30
Sort document type in the dropdownlist when creating a new node in Umbraco.
/* From web.config or some other config place */
<add key="CreateContentSortOrder" value="Content page,Section page,some other page type name" />
/* In /umbraco/create/content.ascx - put the code in the bottom */
<%
var createContentSortOrder = ConfigurationManager.AppSettings["CreateContentSortOrder"];
if (!String.IsNullOrWhiteSpace(createContentSortOrder))
{ %>
<script type="text/javascript">
$(function () {
// Typed
var ids = Model.Content.GetPropertyValue<string>("mNTP", true, "").Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
var items = Umbraco.TypedContent(ids);
// Dynamic
@if (CurrentPage.HasValue("mNTP", true))
{
var ids = CurrentPage._mNTP.Split(',');
var items = Umbraco.Content(ids);
foreach (var item in items)
@sniffdk
sniffdk / Testimonials.cs
Last active December 12, 2015 04:58 — forked from mattbrailsford/Testimonials.cs
Searching for nodes in the new Umbraco v6 API via Examine
// It's properly more correct to search on NodeTypeAlias (or DocumentTypeAlias as it's called in the new API)
var criteria = ExamineManager.Instance.DefaultSearchProvider.CreateSearchCriteria().NodeTypeAlias("Testimonial").Compile();
var testimonials = Model.Content.AncestorOrSelf(1)
.Sibling("Repository")
.Search(criteria);
// Or perhaps even just this, no traversing is need, performance should be the same, as nodes in Lucene aren't hierarchically stored
var criteria = ExamineManager.Instance.DefaultSearchProvider.CreateSearchCriteria().NodeTypeAlias("Testimonial").Compile();
var testimonials = Model.Content.Search(criteria);
@sniffdk
sniffdk / gist:4717777
Created February 5, 2013 21:22
Get root sibling node in Umbraco v6
@{
var root = Model.Content.AncestorOrSelf(1);
var repository = root.Sibling("Repository");
}
public interface IBaseItem
{
int Id { get; set; }
string Name { get; set; }
}
public class ItemsIndex : AbstractIndexCreationTask<IBaseItem>
{
public ItemsIndex()
{
private HttpContext _context;
public void ProcessRequest(HttpContext context)
{
_context = context;
context.Response.ContentType = "text/plain";
context.Response.Buffer = false;
foreach (var d in Document.GetRootDocuments())