Global Fields
Global Fields
A Global field is a reusable field (or group of fields) that you can define once and reuse in any content type within your stack. This eliminates the need (and thereby time and efforts) to create the same set of fields repeatedly in multiple content types.
Example:
const globalField = stack.globalField('global_field_uid'); // For a single globalField with uid 'global_field_uid'| Name | Type | Description |
|---|---|---|
| globalFieldUid | string | UID of the Global field |
find
The find method retrieves all the global fields of the stack.
Example:
import { BaseGlobalField, FindGlobalField } from '@contentstack/delivery-sdk'
interface ImageField extends BaseGlobalField {
format: string
// other props
}
const result = await stack
.globalField()
.find<ImageField>();fetch
The fetch method retrieves the global field data of the specified global field.
Example:
import { BaseGlobalField } from '@contentstack/delivery-sdk'
const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
interface ImageField extends BaseGlobalField {
format: string
// other props
}
const result = await stack
.globalField('global_field_uid')
.fetch<ImageField>();includeBranch
The includeBranch method includes the branch details in the result for single or multiple global fields.
Example:
const result = await stack
.globalField('global_field_uid')
.includeBranch()
.find<ImageField>();