Creating a Property Editor

A guide to creating a property editor in Umbraco.

Overview

This guide explains how to set up a property editor and hook it into Umbraco's Data Types. It also covers the creation of a basic property editor and how to test the property editor.

The steps covered in part one are:

This tutorial uses TypeScript and Lit with Umbraco. It is expected that your package is already set up to use TypeScript and Lit.

To see how to set up an extension in Umbraco using TypeScript and Lit, read the article Creating your first extension.

Resources

This tutorial will not go in-depth on how TypeScript and Lit work. To learn about TypeScript and Lit, you can find their documentation below:

The End Result

At the tutorial's end, the result is a Umbraco Suggestions Data Type, registered in the backoffice, and assigned to a Document Type. This Data Type can create and suggest values.

circle-info

At each step, you will find a dropdown for suggestions-property-editor-ui.element.ts and umbraco-package.json to confirm your placement for code snippets.

Setting up a plugin

  1. Follow the Vite Package Setup by creating a new project folder called "suggestions" in App_Plugins.

  2. Create a manifest file to define and configure the property editor using either JSON or TypeScript.

Create a manifest file named umbraco-package.json at the root of the suggestions folder, and add the following code:

circle-info

The umbraco-package.json files are cached by the server. When creating new umbraco-package.json files, it might take a few seconds before those are loaded into the server cache.

circle-info

It is important to select the right propertyEditorSchemaAlias as it affects how the Property Editor data is made available when rendering the website.

In this example, we selected the Umbraco.Plain.String because we want a string value. For more options, see the default Property Editor Schema aliases article.

Creating a Web Component

Create the web component for the property editor.

  1. Create a file in the src folder with the name suggestions-property-editor-ui.element.ts

  2. In this new file, add the following code:

  1. In the vite.config.ts file replace the entry to the newly created .ts file:

The basic parts of the editor are now complete, namely:

  • The package manifest, telling Umbraco what to load

  • The web component for the editor

  1. Reload the backoffice.

Registering the Data Type in Umbraco

  1. Add the newly added property editor "Suggestions" in the Document Type and save it.

Suggestions Property Editor

The assigned property's value can now be edited with the new property editor.

  1. Check out the content where you will see the property editor that looks like this:

Adding styling and setting up events in the Web Components

Start by creating an input field and some buttons to style and hook up to events.

  1. Update the render method to include some input fields and buttons in the suggestions-property-editor-ui.element.ts file:

circle-info

The Umbraco UI library is already a part of the backoffice, which means it can be used immediately.

  1. Add some styling. Update the import from lit to include css and UmbTextStyles:

  1. Add the CSS:

It should now look something like this:

chevron-rightSee the file: suggestions-property-editor-ui.element.tshashtag

It's starting to look good! Next, set up the event logic.

Setup Event Logic

Setup Input Field

Start with the input field. When typing something in the input field, the property editor's value should change to the input field's current value.

A change event must be dispatched, which can be done in two ways:

  • Using new CustomEvent('change') or

  • Using new UmbChangeEvent() which is recommended as you can leverage the core class

  1. Add the import so the event can be used:

  1. Add the event to the property editor:

Look at the suggestions button next.

Setup Suggestions Button

  • When pressing the suggestion button, the text should update to the suggestion received. Similar to how the value of the property editor changes when writing in the input field.

  • The value should also change when pressing the suggestion button.

  1. Update the import for Lit:

  1. Add suggestions to the property editor:

  1. Update the suggestion button in the render method to call a onSuggestion method when pressing the button:

chevron-rightSee the entire file: suggestions-property-editor-ui.element.tshashtag
  1. Clear your cache, reload the document, and see the Suggestions Data Type running.

When saving or publishing, the value of the Data Type is automatically synced to the current content object and sent to the server.

Learn more about extending this service by visiting the Property Editors page.

Going further

With all the steps completed, a Suggestion Data Type is now running in the property editor.

The next part covers adding configurations to the property editor.

Last updated

Was this helpful?