After creating a custom widget, it is likely that you will also want to include custom attributes that the end user can access and alter as needed based on the widget.
## ContentFieldAttributes
ContentFieldAttributes can be used to customize the display/editing of a property on a widget. An example of this is adding a Country Selection ability to a widget.
First create a new class with the following content. In this example we are inheriting from an existing attribute. An important thing to note is that we override GenericType to return typeof(drop-downContentFieldAttribute). This is required to make use of the existing html template, without it a new html template would be required.
If a custom html template is needed for our new attribute, then the Template property can be set in our new class. To make sure of a razor view from the extensions project, this value needs to start with "\~/Extensions/" followed by the path to the view inside of the project.
Then in the extensions project a razor view needs to exist at Views/ContentItemFields/CountrySelector.cshtml. This razor view needs to be an embedded resource. By default the extensions project will embed all razor views.
This example is a copy of the drop-down.cshtml view, with the @model declaration modified to use our new Extensions.CountrySelector.
To make use of the new ContentFieldAttribute, add a new property to a custom widget. Then include your new attribute on the property. When editing this widget, the CountrySelector will be used.