Skip to content

Instantly share code, notes, and snippets.

View TimGeyssens's full-sized avatar

Tim Geyssens TimGeyssens

View GitHub Profile
using System.Web.Security;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Events;
using Umbraco.Core.Scoping;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using System.Linq;
using System;
using Umbraco.Core.Security;
@TimGeyssens
TimGeyssens / ISiteService.cs
Last active September 4, 2020 08:42
Extending the UmbracoHelper in Umbraco v8
using Umbraco.Web.PublishedModels;
namespace MyWebSite.Custom
{
public interface ISiteService
{
Website GetWebsite(int id);
SearchPage GetSearchPage(int id);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Umbraco.Community.Contentment.DataEditors;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web;
namespace MyWebsite.DataSources
{
using System.Linq;
static public class IEnumerableHelper
{
static public Object<T> TakeFirst<T>(this IEnumerable<T> items)
{
return items.Take(1).First();
}
}
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySite.Models.PropEditors;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
<div ng-controller="Custom.ThemaColorPickerController">
<ul style="list-style: none;">
<li ng-repeat="color in colors">
<label >
<input type="radio" name="pageNumber" ng-model="model.value" ng-value="color.Name" /> {{color.Name}}
<div style="display:block;height:30px;width:30px;background-color:{{color.Code}};border:1px #000 solid;float:left;margin-right:10px;"></div>
</label><br/>
</li>
</ul>
</div>
var app = angular.module("umbraco");
angular.module("umbraco").controller("Custom.ThemaColorPickerController",
function ($scope, $routeParams, $location, $http) {
$http.get("backoffice/Custom/ThemaColorPickerApi/GetAvailableColors?page=" + $routeParams.id).then(function (response) {
$scope.colors = response.data;
});
namespace MyWebsite.Controllers.PropEditors
{
[Umbraco.Web.Mvc.PluginController("Custom")]
public class ThemaColorPickerApiController: UmbracoAuthorizedApiController
{
public IEnumerable<Color> GetAvailableColors(int page) {
var colors = new List<Color>();
var themePage = Services.ContentService.GetAncestors(page).FirstOrDefault(x => x.HasProperty("theme"));
{
propertyEditors: [
{
alias: "Custom.ThemaColorPicker",
name: "Thema ColorPicker",
group: "Pickers",
icon: "icon-palette",
editor:{
view: "~/App_Plugins/ThemaColorPicker/ThemaColorPicker.html",
valueType: "STRING"
public class ApplicationComposer : ComponentComposer<ApplicationComponent>, IUserComposer
{
public override void Compose(Composition composition)
{
StaticFileHasher.HashFiles(umbracoApplication.Server.MapPath("~/css"), umbracoApplication.Server.MapPath("~/js"));
base.Compose(composition);
}
}