Sanity Library Reference Docs
    Preparing search index...

    Interface Template<Params, Value>

    An initial value template is a template that can be used to create a new documents.

    This allows a document type to have multiple different starting values while having the same shared schema definition. Using parameters allows for dynamic template values.

    As the name implies, these are initial values, not default values. The distinction is that the initial value is only set when the document is created - it is not "merged" into existing documents that may lack values for fields.

    All document types will by default (automatically, behind the scenes) have an initial value template generated for them, which will have the same ID as the schema type name. The value of this template will be the value of the initialValue property on the schema type definition, or an empty object if none is set.

    interface Template<Params = any, Value = any> {
        description?: string;
        icon?: ComponentType;
        id: string;
        parameters?: TemplateParameter[];
        schemaType: string;
        title: string;
        value: InitialValueProperty<Params, Value>;
    }

    Type Parameters

    • Params = any
    • Value = any
    Index

    Properties

    description?: string

    Template description. Rendered in places such as the "new document" dialog. Optional.

    No longer used

    icon?: ComponentType

    Template icon. Rendered in places such as the "new document" dialog. Optional. Inferred from the schema type icon if not set.

    id: string

    Template ID. Automatically generated templates will have the same ID as the schema type name.

    parameters?: TemplateParameter[]

    Array of parameters the template accepts. Currently not used (any parameters are accepted), but by defining parameters, the templates that require parameters can be identified and excluded from UIs that do not provide them.

    schemaType: string

    Schema type name the template belongs to. For the automatically generated templates, this will be equal to the id property.

    title: string

    Template title.

    Value to use as initial value. Can either be a static object value, or a function that resolves to an object value. If using a function, it can be given a set of parameters, which can then determine the value that is returned.