Per Nergård (MVP)
+1
Jun 5, 2026
visibility 325
star star star star star
(0 votes)

Automatic assign of content reference properties on content creation

A long time ago I was tired of configuring setting properties on a settings page when deploying new functionality that needed global settings, so I did a way of accomplishaing that with attributes from the settings page.

Earlier this week I got tired of it again and did another version for CMS 13 but this time I did it from the other way around with an attribute on the content type. 

Old blog post here: 2019

So the idea is that when building a new function and we need to configure a settings property to point to a new content type for some shared functionality you could configure that via an attribute on the content type so after deploy you just create your new page and it automatically wires up the setting for you.  Done in an Alloy site so thats why I use StartPage.

Maybe not a super big problem if you just delploying a new features but if setting up a boilerplate solution of some sort from scratch it will make your life much easier.

// Auto-match: the settings property whose [AllowedTypes] most specifically accepts ContactPage is used.
[RegisterIn(typeof(StartPage))]
public class ContactPage : SitePageData { }

// Explicit property: recommended when the settings property allows a broad base type (e.g. PageData).
[RegisterIn(typeof(StartPage), nameof(StartPage.ContactsPageLink))]
public class ContactPage : SitePageData { }

// React on creation instead of publish.
[RegisterIn(typeof(StartPage), Trigger = RegisterTrigger.Created)]
public class ContactPage : SitePageData { }


Code over at my GitHub. Pnergard AutoRegister

Jun 05, 2026

Comments

error Please login to comment.
Latest blogs
Optimizely Commerce 14 Now Supports .NET 10

In my previous post, Optimizely CMS 12 Now Fully Supports .NET 10 , I noted one remaining limitation: Commerce 14 (Commerce Connect) did not yet...

Bien Nguyen | Aug 7, 2026

The Top 10 Things I'm Actually Using AI For

A while back I wrote about ReviewPR, an Azure Function that uses AI to review Azure DevOps pull requests. That was one specific use case, but over...

KennyG | Aug 5, 2026

Drag-and-Drop Reordering for Commerce Media Collection in Optimizely Commerce Connect

Optimizely Commerce Connect ships a polished asset editor for the CommerceMediaCollection  property on catalog entries. It lets editors add, remove...

Linh Doan Cuu | Aug 5, 2026

Order tabs with drag and drop V2

I earlier did a very simple Blazor version to be able to sort tabs with drag and drop. I wanted to update it a bit and also display how the tabs ar...

Per Nergård (MVP) | Aug 4, 2026