diff --git a/content/docs/api/db/type/contents.lr b/content/docs/api/db/type/contents.lr index 6d91f44c..3c69f01a 100644 --- a/content/docs/api/db/type/contents.lr +++ b/content/docs/api/db/type/contents.lr @@ -37,7 +37,7 @@ class MyThingType(Type): return raw.value def setup_env(self, **extra): - self.env.types['mything'] = MyThingType + self.env.add_type(MyThingType) ``` For more information see [value_from_raw :ref](value-from-raw/). diff --git a/content/docs/api/db/type/value-from-raw/contents.lr b/content/docs/api/db/type/value-from-raw/contents.lr index d6359d7a..80c5cc3f 100644 --- a/content/docs/api/db/type/value-from-raw/contents.lr +++ b/content/docs/api/db/type/value-from-raw/contents.lr @@ -36,7 +36,7 @@ class LocationType(Type): return (lng, lat) def setup_env(self, **extra): - self.env.types['location'] = LocationType + self.env.add_type(LocationType) ``` ## Raw Value diff --git a/content/docs/api/environment/add-type/contents.lr b/content/docs/api/environment/add-type/contents.lr new file mode 100644 index 00000000..c211260c --- /dev/null +++ b/content/docs/api/environment/add-type/contents.lr @@ -0,0 +1,28 @@ +title: add_type +--- +signature: type +--- +summary: Adds a new field type to the environment. +--- +type: method +--- +version_added: 2.0 +--- +body: + +This registers a new [Field Type :ref](../../db/type/) with the environment + +## Example + +```python +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) +```