Skip to content

Instantly share code, notes, and snippets.

View abjerner's full-sized avatar

Anders Bjerner abjerner

View GitHub Profile
@abjerner
abjerner / UmbracoGuidExtensions.cs
Created July 15, 2015 17:56
UmbracoGuidExtensions.cs
using System;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web.PublishedCache;
public static class UmbracoGuidExtensions {
/// <summary>
/// Gets an instance of <code>IPublishedContent</code> based on the specified <code>guid</code>. GUIDs are not
/// available in the content cache, so a lookup will be made in the database (or the runtime cache if the GUID
@abjerner
abjerner / Members.cshtml
Created June 19, 2015 17:42
Listing all members in Umbraco:
@using Umbraco.Core.Services
@inherits UmbracoViewPage
@{
IMemberService ms = UmbracoContext.Application.Services.MemberService;
int total;
foreach (IMember member in ms.GetAll(0, Int32.MaxValue, out total)) {
@abjerner
abjerner / Translations.js
Created April 22, 2015 08:31
Adding custom translations to Umbraco backoffice
$(window).load(function () {
var ev = angular.element(document).injector().get('eventsService');
ev.on('localizationService.updated', function () {
var ls = angular.element(document).injector().get('localizationService');
ls.dictionary['bacon_omgbacon'] = 'OMG BACON';
  • Create a common package - could be called Our.NuGetPackageActions for packages to use. Ths package:

    • Looks for packages at startup (eg. implementing a certain interface)

    • Keeps track of new install and updates via temp files stored in App_Data sub folder

  • Lets you have events for "Installed" and "Updated". There could also be an "Uninstalled" event although the DLL has been removed ad this point.

@abjerner
abjerner / Dashboard.md
Created January 19, 2015 18:40
Adding a dashboard for a custom section

Open /config/Dashboard.config, then add something like:

<section alias="CustomDashboardSection">
  <areas>
    <area>myApp</area>
  </areas>
  <tab caption="Welcome">
    <control addPanel="true" panelCaption="">
/App_Plugins/myApp/dashboard.html

By using my Skybrud.Umbraco.GridData package (which introduces a strongly typed model for the Grid), indexing the new Grid in Umbraco 7.2 is quite easy.

At Skybrud.dk we typically create a class named ExamineIndexer that takes care of the Examine related events. This class should be initalized during Umbraco startup like this:

using Umbraco.Core;

namespace FanoeTest {

 public class Startup : ApplicationEventHandler {
@abjerner
abjerner / Contour.md
Created December 3, 2014 18:29
Quick guide to insert Contour <script> tags at the bottom of the page rather than in context.

Open /umbraco/plugins/umbracoContour/views/Form.cshtml and look for the following line:

@Html.Partial(FormViewResolver.GetScriptView(Model.FormId), Model)

Replace it with these lines:

List temp = HttpContext.Current.Items["ContourScripts"] as List;
@abjerner
abjerner / PreValueEditor.html
Created October 13, 2014 19:47
Example of a quick Umbraco package
<div ng-controller="PreValueEditor.Controller">
<label>
<input type="checkbox" ng-model="model.value.a" />
Option A
</label>
<label>
<input type="checkbox" ng-model="model.value.b" />
Option B
public class ParentPage {
public int Id { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public IEnumerable<TestPage> Pages { get; set; }
@abjerner
abjerner / Editor.js
Created September 27, 2014 23:08
Example controller for a AngularJS property editor in Umbraco 6
angular.module('umbraco').controller('GoogleAddressSearchController', ['$scope', '$http', function ($scope, $http) {
if (!$scope.model.address) $scope.model.address = '';
$scope.address = $scope.model.address;
$scope.suggestions = [];
$scope.addressKeyDown = function () {