Skip to main content

Custom fields and content types in the API

Staff can create content types (for example "Event", "Parish priest") and custom fields (for example "Date", "Place") in the admin site. Each entry returns two related fields:

FieldTypeMeaning
contentTypestring | nullThe content type's slug; null for regular posts and for static pages.
metaobjectThe custom field values, keyed by the field key.

Present in both list items and the detail response.

Agree on the keys with staff first​

The public API does not return field definitions (display name, type, required or not). meta is only key/value pairs. So:

  1. Agree with staff on the list of content types and field keys your design relies on, for example the type su-kien with ngay-dien-ra (date) and dia-diem (text).
  2. Write your design around contentType and those keys.
  3. Always treat every key as possibly absent: optional fields, fields added after the post was written, untranslated per-language values, or staff changing the structure later.

A field key is a slug (lowercase letters, digits, -), at most 40 characters, unique within a site.

Values by field type​

Field typeJSON value in metaSafe display
Short textstring, at most 300 characters, one linePrint it as text.
Long textstring, at most 5000 characters, may contain line breaksPrint it as text, turning line breaks into <br> or using CSS white-space: pre-line. Do not insert it as HTML.
Linkstring, always starting with https://Use it as href; add rel="noopener noreferrer".
NumbernumberFormat it for the language (Intl.NumberFormat).
Datestring in YYYY-MM-DD format (date only, no time)Parse it as a calendar date, not through new Date(…) in local time, or it may shift by a day.
Yes/noboolean
Choicestring: the option's value (slug), not its labelMap the value to a display label yourself.
Imageobject with url (a full https:// address)Use url as src. The object also has an internal ID key: ignore it.

Some fields are shared by all languages (for example dates, images), others are per language (for example a place written in Vietnamese and in English). The meta you receive already merges both kinds for the locale you asked for. An untranslated per-language value is absent; it does not fall back to the primary language.

Example: displaying an "Event"​

type Meta = Record<string, unknown>

const text = (v: unknown): string | null => (typeof v === 'string' && v.trim() !== '' ? v : null)

function calendarDate(v: unknown, locale: string): string | null {
if (typeof v !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(v)) return null
const [y, m, d] = v.split('-').map(Number)
// Format in UTC so the calendar day never shifts with the visitor's time zone.
return new Intl.DateTimeFormat(locale, { dateStyle: 'long', timeZone: 'UTC' }).format(new Date(Date.UTC(y, m - 1, d)))
}

function imageUrl(v: unknown): string | null {
if (typeof v !== 'object' || v === null) return null
const url = (v as { url?: unknown }).url
return typeof url === 'string' && url.startsWith('https://') ? url : null
}

function eventDetails(entry: { contentType: string | null; meta: Meta }, locale: string) {
if (entry.contentType !== 'su-kien') return null
return {
date: calendarDate(entry.meta['ngay-dien-ra'], locale),
place: text(entry.meta['dia-diem']),
poster: imageUrl(entry.meta['anh-poster']),
}
}

The keys su-kien, ngay-dien-ra, dia-diem and anh-poster above are only examples; use the keys you agreed on with staff.

"Unlisted" content types​

Staff can set a content type as unlisted. Posts of that type are not in the general list, search or "Most read", but they are still in category and tag lists and can still be opened by slug. Use this for items that have their own page (for example an "Events" category shown as a calendar) and that you do not want mixed into the main news feed.

Was this page helpful?