Skip to content

Instantly share code, notes, and snippets.

View AndyButland's full-sized avatar

Andy Butland AndyButland

View GitHub Profile
IConfigurationSection mySettingsSection = builder.Configuration.GetSection("MySettings");
builder.Services.Configure<MySettings>(mySettingsSection);
services.PostConfigure<MySettings>(options =>
{
if(!options.MyOptions.Any(x => x.Alias == "itemOne"))
{
options.MyOptions.Add(new MyOption { Alias = "itemOne", Value = 0 });
}
public class MySettings
{
public List<MyOption> MyOptions { get; set; } = new List<MyOption>
{
new MyOption { Alias = "itemOne", Value = 0 },
new MyOption { Alias = "itemTwo", Value = 0 },
}
}
{
"MySettings": {
"MyOptions": [
{
"Alias": "itemOne",
"Value": 1,
},
{
"Alias": "itemTwo",
"Value": 2,
public class MySettings
{
public List<MyOption> MyOptions { get; set; }
}
public class MyOption
{
public string Alias { get; set; }
public int Value { get; set; }
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;
namespace Umbraco.Deploy.OnPrem.TestSite.Business
{
public class DictionaryCacheRefresherNotificationHandler : INotificationHandler<DictionaryCacheRefresherNotification>
{
@using Umbraco.Core.Services
@using Umbraco.Core
@using Umbraco.Core.Deploy
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@using Umbraco.Web.Models
@{
Layout = "Master.cshtml";
@AndyButland
AndyButland / AjaxFormPage.cshtml
Last active June 7, 2024 09:40
Umbraco Forms API usage with vanilla JavaScript
@*
Demonstration of using the Umbraco Forms 13 API for retrieving the definition of a form, rendering it and posting an entry.
It's based off an Umbraco content item with a property with alias "Form", of type "Form Picker".
*@
@using Microsoft.AspNetCore.Antiforgery
@using Microsoft.Extensions.Options;
@using Umbraco.Cms.Web.Common.PublishedModels;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.AJaxformPage>
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
public void ConfigureServices(IServiceCollection services)
{
services.AddUmbraco(_env, _config)
.AddBackOffice()
.AddWebsite()
.AddComposers()
.Build();
services.AddMyLibrary();
services.ConfigureOptions<MyConfigureOptions>();
using Microsoft.Extensions.Options;
using Umbraco.Cms.Web.Common.ApplicationBuilder;
namespace MyApp
{
public class MyConfigureOptions : IConfigureOptions<UmbracoPipelineOptions>
{
public void Configure(UmbracoPipelineOptions options)
{
options.AddFilter(new MyPipelineFilter());
using Microsoft.AspNetCore.Builder;
using Umbraco.Cms.Web.Common.ApplicationBuilder;
namespace MyApp
{
public class MyPipelineFilter : UmbracoPipelineFilter
{
public MyPipelineFilter() : base(nameof(MyPipelineFilter))
{
PostPipeline = app =>