Last updated
Was this helpful?
Last updated
Was this helpful?
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 we can test our property editor.
The steps we will go through in part one are:
This tutorial uses TypeScript and Lit with Umbraco. It is expected that your package is already .
To see how to set up an extension in Umbraco using TypeScript and Lit, read the article .
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:
At the tutorial's end, we'll have a Umbraco Suggestions Data Type, registered in the backoffice, and assigned to a Document Type. This Data Type can create and suggest values.
Then create the manifest file named umbraco-package.json
at the root of the suggestions
folder. Here we define and configure our dashboard.
Add the following code to umbraco-package.json
:
Now let's create the web component we need for our property editor.
Create a file in the src
folder with the name suggestions-property-editor-ui.element.ts
In this new file, add the following code:
In the vite.config.ts
file replace the entry
to our newly created .ts
file:
Now our basic parts of the editor are done, namely:
The package manifest, telling Umbraco what to load
The web component for the editor
Reload the backoffice.
Add our newly added property editor "Suggestions" in the Document Type and save it.
We can now edit the assigned property's value with our new property editor.
Check out the content where you will see the property editor that looks like this:
Let's start by creating an input field and some buttons that we can style and hook up to events.
Update the render method to include some input fields and buttons in the suggestions-property-editor-ui.element.ts
file:
Add some styling. Update the import from lit to include css
and UmbTextStyles
:
Add the CSS:
It should now look something like this:
It's starting to look good! Next, let's look into setting up the event logic.
Let's start with the input field. When we type something in the input field, we want the property editor's value to change to the input field's current value.
We then have to dispatch a change
event 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
Add the import so the event can be used:
Add the event to the property editor:
Let's look at the suggestions button next.
When we press the suggestion button we want the text to update to the suggestion that we get. Similar to how the value of our property editor changes when we write in the input field.
We also want the value to change when we press the suggestion button.
Update the import for Lit:
Add suggestions to the property editor:
Update the suggestion button in the render method to call a onSuggestion
method when we press the button:
Clear your cache, reload the document, and see the Suggestions Data Type running.
When we save or publish, the value of the Data Type is now automatically synced to the current content object and sent to the server.
With all the steps completed, we have created a Suggestion Data Type running in our property editor.
In the next part, we will look at adding configurations to our property editor.
Follow the by creating a new project folder called "suggestions
" in App_Plugins
.
In this example, we selected the Umbraco.Plain.String
because we want a string value. For more options, see the article.
Learn more about extending this service by visiting the page.
A guide to creating a property editor in Umbraco.