Custom DataTypes in Umbraco
Umbraco, an Open Source CMS built on the Microsoft ASP.NET Framework. Umbraco makes it easy to implement custom datatypes using the built-in usercontrol wrapper to configure a custom property within a pre-created Document Type.
There are some many cases when a custom datatype will be really useful instead of using one of the built-in Umbraco’s datatypes, in this example we will create a custom datatype to store information of each content item:
- Owner Name
- Owner Role
- Creation Date
- and Modification Date
This simple form will display regular .NET controls like textboxes and calendars. The first step is to add a reference to the umbraco.editorControls assembly.
To create a custom control, you must:
- Add a new user Control to our usercontrols folder
- Add the user control mark-up
- The new usercontrol implements the
umbraco.editorControls.userControlGrapper.IUsercontrolDataEditorinterface, and then implements the interface member value.
- Define the Umbraco value on postback.
- Move all the new components to your Umbraco folders.
- Go to Umbraco control panel and click on “Developer” section.
- Create a new Data Type called: CustomDataType.
- Select the Umbarco usercontrol wrapper as “Render Control”, and then click “Save” to enable extra options.
- Select our new usercontrol in the “Usercontrol” option.
- Go to the “Settings” section to add a custom properties on a selected Document Type.
- First, add a new Tab. For this example, we’ll call it MyTab. the new tab can be added in the “Tabs” settings.
- Then go to the “Generic properties” and click on “Add New Property”. Here you can enter the Property Name, Type (select our CustomDataType), and the Tab to be displayed (select our MyTab), finally click on “Save”.
To see our new changes, we can create a new content item of the same document type we have selected. We can also see our changes in the created content items of this document type
- Go to “MyTab” and you will see our custom datatype.
When you click on “Save”, the Umbraco value member is assigned and the value is stored. You can click on any other item and then go back to confirm that our custom datatype is showing the saved information.
In the end, you can see how easy is to extend data-types functionality in Umbraco, this really useful feature can save a lot of time and improve the way we manage content’s properties, using the .net framework is easy to implement any custom functionality that simply integrates with Umbraco.