Generic Fields

Håkan Edling edited this page Apr 2, 2018 · 1 revision

Generic fields are custom fields that are built around Generic Types. These fields work in the same way as custom field but has a number of extra rules to them.

Create a base class

A generic field must have a non-generic base class. This type will be used when resolving the name of the EditorTemplate. For example:

public abstract class MyGenericFieldBase : Piranha.Extend.IField

[Field(Name = "My Generic")]
public class MyGenericField<T> : MyGenericFieldBase

Create the EditorTemplate

Next up is creating the EditorTemplate that should render the field. The template should be located in:


The name should be the same as the base class of your generic field, in this example it would be MyGenericFieldBase.cshtml.

@model MyNamespace.MyCoolFieldBase

<div>Some HTML code here</div>

##. Register each usage of the field

Since field registration is type based you need to register each use of your generic field, for example:

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.