lektor.types.
Type
(env, options
)The fields in Records use types to specify the behavior of the values. Lektor comes with a wide range of built-in field types but it is possible to build your own by subclassing types class. A type is instantiated with two parameters: a reference to the Environment that it belongs to and a dictionary with configuration options from the ini file.
A field type has to implement the value_from_raw
method and set the widget
property as a very basic requirement.
To create a type you need to create a subclass. The name of the class needs
to match the type name. If you want to name your type mything
then it
needs to be called MyThingType
. Afterwards you can register it with the
environment in setup_env:
from lektor.types import Type
class MyThingType(Type):
widget = 'singleline-text'
def value_from_raw(self, raw):
return raw.value
def setup_env(self, **extra):
self.env.add_type(MyThingType)
For more information see value_from_raw.
There is a more complete example in the Plugin How To.
Returns the type information as JSON.
Main method to override to implement the value conversion.
An attribute that identifies the widget to use in the admin panel.
Comments