Skip to content

k.content ​

Query, create, update, delete, reorder, relate, and localize Kooboo ContentFolders and TextContent items

Execution ContextPrerequisitesTypical Use
All server-side scripts (API, View, Page, Layout, Jobs)Create ContentTypes and Content Folders in Admin firstFetching articles/catalogs, single-content config, CRUD, localization, and relations

k.content exposes a typed entry point for every Content Folder configured in the current site, supporting folder reads, pagination, sorting, filtering, CRUD mutations, reordering, related content links, and multilingual culture queries.

Quick Start ​

js
// Fetch the latest 5 online items from Blog and check culture online status
const latest = k.content.Blog.all({
  orderByDescending: "creationDate",
  take: 5
})

const firstPost = k.content.Blog.get("welcome-post")
const statusMap = firstPost ? k.content.onlineStatus(firstPost.id) : null

Quick Reference ​

Method / PropertyDescriptionReturns
k.content.<folderName>Access list-folder operations or the single item on Single-Content foldersfolderBase<T, M> / T | null
onlineStatus(contentId)Get per-culture online status flags for an itemRecord<string, boolean>
<folder>.all(options?)List folder items (up to 999 online items within availability window by default)T[]
<folder>.get(nameOrId)Fetch a single item by id or userKeyT | null
<folder>.add(content)Create a new item in the folder and return itT
<folder>.update(content)Persist edits to an existing itemvoid
<folder>.delete(nameOrId)Delete an item by object, id, or userKeyvoid
<folder>.find(query, options?)Return the first item matching a condition string or filter objectT | null
<folder>.findAll(query, options?)Return all items matching a condition string or filter objectT[]
<folder>.findAllByCategory(folder, slugOrId, options?)Fetch items linked to a specific category itemT[]
<folder>.move(source, prev?, next?)Reorder an item relative to adjacent itemsvoid

Content Type and Folder Configuration

Content types and folders must be created in the admin console before querying them. See Content Types and Content Folder Settings.

Folder and Content Access ​

Dynamic properties on k.content match the folder names configured in the site (for example Blog, Creator, news). Folders operate in one of two modes:

List Folders ​

Standard folders mounted on k.content.<folderName> expose all, get, add, update, delete, find, findAll, findAllByCategory, and move:

js
// Fetch all online items in the Blog folder (up to 999 by default)
const posts = k.content.Blog.all()

// Fetch a single item by id or userKey
const post = k.content.Blog.get("welcome-post")

Single-Content Folders ​

When a folder is configured in Single Content mode in the admin console, k.content.<folderName> resolves directly to the single item object itself rather than folder methods; if the folder has no available item yet, it returns null (undefined is only returned when the folder itself does not exist).

js
// Assuming siteInfo is configured as a single-content folder
const info = k.content.siteInfo
const companyName = info ? info.companyName : ""

onlineStatus() ​

Checks the per-culture online status map of a content item:

ParameterTypeRequiredDescription
contentIdstringYesContent item id or userKey

Returns: Record<string, boolean> mapping each culture code to its online flag.

js
const status = k.content.onlineStatus(post.id)
// Example output: { en: true, zh: false }

Folder Read and Write Methods ​

The following methods are available on list-mode folders (k.content.<folderName>):

all() ​

Returns items in the folder (by default, up to 999 online items within their active availability window).

ParameterTypeRequiredDescription
optionsQueryOptionsNoOptional pagination, sorting, filtering, and field projection options

Returns: Array of content items T[].

js
const latest = k.content.Blog.all({
  orderByDescending: "creationDate",
  take: 10
})

get() ​

Retrieves a single item by id or userKey. It respects the active request culture, verifies folder ownership, and checks scheduled availability dates (OnAvailableDate), but does NOT filter out items with online == false.

ParameterTypeRequiredDescription
nameOrIdstringYesContent id (GUID) or userKey

Returns: Matching item T, or null if missing, in another folder, or outside its availability dates. Check item.online explicitly (or use find() / all(), which filter offline items by default) when offline items must be hidden.

js
const item = k.content.Blog.get("ef4e634b-87a6-b2d2-ec14-5139287beb6e")
if (item && item.online) {
  // Only handle online content
}

add() ​

Creates a new content item in the folder and returns the persisted item T. Common optional system fields include userKey, slug, sequence, online, enableAvailableDate, availableStartDate, and availableEndDate.

ParameterTypeRequiredDescription
contentobjectYesCustom content-type fields plus optional built-in system fields

Returns: The newly created content item T.

js
const created = k.content.Creator.add({
  username: "alice",
  email: "alice@example.com",
  online: true,
  sequence: 10
})

Multilingual Writes

Multilingual field values are stored under the active request culture (k.request.culture); non-multilingual fields apply across all cultures.

update() ​

Saves changes to an existing item. content must be a KTextContent object returned by get(), find(), all(), or add() after modifying its fields; passing a plain JS object literal (e.g. { id, username }) is silently ignored and performs no update.

ParameterTypeRequiredDescription
contentKTextContentYesMust be a KTextContent object returned by get(), find(), all(), or add(); plain JS object literals are silently ignored

Returns: void.

js
const creator = k.content.Creator.get(created.id)
if (creator) {
  creator.username = "alice-updated"
  k.content.Creator.update(creator)
}

delete() ​

Deletes the specified content item from the folder.

ParameterTypeRequiredDescription
nameOrIdanyYesContent object, id, or userKey

Returns: void.

js
k.content.Creator.delete(created.id)
// Or pass the item object directly
// k.content.Creator.delete(created)

find() & findAll() ​

Queries items using a string condition expression or a filter object:

  • find(query, options?): Returns the first matching item T (take fixed to 1), or null if none match.
  • findAll(query, options?): Returns all matching items T[].
ParameterTypeRequiredDescription
querystring | objectYesString query expression or filter object
optionsQueryOptionsNoPagination, sorting, and filtering options

Returns: find() returns T | null; findAll() returns T[].

js
// 1. String condition query
const one = k.content.Creator.find("username == 'alice'")
const matched = k.content.Blog.findAll("tags == 'tech' && online == true", {
  orderByDescending: "creationDate",
  take: 20
})

// 2. Object filter query
const exact = k.content.Creator.find({ email: "alice@example.com" })
const filtered = k.content.Creator.findAll(
  {
    $and: [
      { creationDate: { $gte: "2020-01-01T00:00:00Z" } },
      { username: { $startswith: "alice" } }
    ]
  },
  { take: 10 }
)

findAllByCategory() ​

Finds all items in the folder linked to a specific category item (when a Category relation is configured on the folder).

ParameterTypeRequiredDescription
categoryFolderstringYesActual category ContentFolder name or folder ID (does not resolve relation aliases; passing an alias that differs from the folder name silently returns [])
categorySlugOrIdstringYesCategory item id, slug, or userKey
optionsQueryOptionsNoSorting, pagination, projection, and offline filter options (take defaults to 10 for this method)

Returns: Array of matching content items T[] (unlike all() / findAll() which default to take: 999, findAllByCategory() defaults to take: 10; pass take explicitly when more items are needed).

js
const categoryBlogs = k.content.Blog.findAllByCategory("Creator", creator.id, {
  take: 10
})

Type Definition Note

findAllByCategory is supported at runtime; generated TypeScript folder interfaces currently omit its signature.

move() ​

Reorders an item within the folder relative to adjacent items.

ParameterTypeRequiredDescription
sourcestringYesid of the item to move
prevstring | nullNoid of the item that should precede source (pass null to place first)
nextstring | nullNoid of the item that should follow source (pass null to place last)

Returns: Returns void at runtime (do not rely on the generated T[] return type annotation).

js
// Move item a immediately after item b (at the end)
k.content.Creator.move(a.id, b.id, null)

Query Syntax and Options ​

String Query Operators ​

OperatorMeaningExample
== / =Equal"status == 'published'"
!= / <>Not equal"status != 'draft'"
> / >= / < / <=Numeric or date comparison"sequence >= 10"
containsSubstring match"title contains 'Kooboo'"
startwithPrefix match (spelled without s)"username startwith 'dev'"
&& / andLogical AND"online == true && views > 100"
|| / orLogical OR"tag == 'news' || tag == 'guide'"
( ... )Grouping parentheses"(a == 1 || b == 2) && online == true"

Object Filter Operators ​

In filter objects { field: { ... } }, pass a literal value for equality or use the following operator keys (case-insensitive):

Operator KeyMeaningExample
$eqEqual{ views: { $eq: 100 } }
$neNot equal{ status: { $ne: 'archived' } }
$gt / $gteGreater than / Greater than or equal{ creationDate: { $gte: '2026-01-01T00:00:00Z' } }
$lt / $lteLess than / Less than or equal{ sequence: { $lte: 50 } }
$startswithPrefix match (alias $startwith){ username: { $startswith: 'user_' } }
$containsSubstring match (alias $contain){ title: { $contains: 'API' } }
$andLogical AND array{ $and: [{ online: true }, { sequence: { $gt: 0 } }] }
$orLogical OR array{ $or: [{ tag: 'a' }, { tag: 'b' }] }

Query Options (QueryOptions) ​

OptionTypeDefaultDescription
includeOfflineDatabooleanfalseInclude offline/unpublished items (alias includeOffline)
excludeEmptybooleanfalseOn multilingual sites, exclude items whose multilingual fields are empty in the active culture
takenumber999 (10 in findAllByCategory)Maximum number of items to return (all() / findAll() default to 999; findAllByCategory() defaults to 10 unless take is passed explicitly)
skipnumber0Number of items to skip for pagination
orderBystring—Field name for ascending sort
orderByDescendingstring—Field name for descending sort
selectstring[]—Limit retrieved custom fields (system fields remain present) to improve query performance
js
const pageItems = k.content.Blog.all({
  includeOfflineData: false,
  excludeEmpty: true,
  orderByDescending: "creationDate",
  skip: 10,
  take: 10,
  select: ["title", "created", "tags"]
})

When Category or Embedded folder relations are configured on a folder in the admin console, read and mutate relationships as follows:

  1. Read related items: Access the property named after the relation alias (or the categorized folder name on the category item) directly on the content object to obtain an array of related items.
  2. Add or remove links: Use item.relatedContent.<RelationName>.add(targetOrId) and .remove(targetOrId) (pass the target item object, id, or userKey).
js
// Fetch main and related items
const blog = k.content.Blog.get(blogId)
const creator = k.content.Creator.get(creatorId)

// Link items
blog.relatedContent.Creator.add(creator.id)

// Re-fetch to read the updated relation array directly by alias
const updatedBlog = k.content.Blog.get(blog.id)
const authors = updatedBlog.Creator

// Remove link
updatedBlog.relatedContent.Creator.remove(creator.id)

For reverse category navigation (reading content items belonging to a category from the category item itself), categoryItem.relatedContent.<ContentFolderName> also supports .all() as well as .add(contentOrId) and .remove(contentOrId). On category or embedded relations under relatedContent.<RelationName>, .all(includeOffline) is also available at runtime.

Multilingual Behavior ​

k.content reads and writes multilingual fields according to the active k.request.culture. Use k.request.setCulture() and k.request.resetCulture() when querying another culture within the same request:

js
// Read Chinese entries, excluding items with empty localized fields
k.request.setCulture("zh")
const zhList = k.content.Blog.all({ excludeEmpty: true })

// Restore the request's original culture
k.request.resetCulture()

Use excludeEmpty: true when you want to filter out entries that have not yet been populated in the target culture.

Built-In System Fields ​

In addition to custom ContentType fields, every item returned by k.content exposes built-in system properties:

FieldTypeDescription
idstringUnique content identifier (GUID)
userKeystringUser-defined or system-generated unique key
slugstringURL-friendly slug (can be passed in add() or generated by Kooboo)
sequencenumberSort order number
onlinebooleanOnline status flag
creationDatestringCreation timestamp (ISO 8601 string)
lastModifiedstringLast modification timestamp (ISO 8601 string)
folderIdstringParent content folder ID
contentTypeIdstringContent type ID
enableAvailableDatebooleanWhether scheduled availability dates are enabled
availableStartDatestring | nullScheduled start date
availableEndDatestring | nullScheduled end date
parentIdstring | nullNot exposed on TextContentCultureView / KTextContent; always reads as null via k.content
versionnumber | nullNot exposed on TextContentCultureView / KTextContent; always reads as null via k.content

Example JSON output:

json
{
  "id": "a1b2c3d4-e5f6-7890-abcd-1234567890ef",
  "userKey": "alice",
  "slug": "alice",
  "sequence": 0,
  "online": true,
  "folderId": "11111111-2222-3333-4444-555555555555",
  "contentTypeId": "66666666-7777-8888-9999-aaaaaaaaaaaa",
  "enableAvailableDate": false,
  "availableStartDate": null,
  "availableEndDate": null,
  "creationDate": "2026-11-21T02:51:43.000Z",
  "lastModified": "2026-11-21T02:51:43.000Z",
  "username": "alice",
  "email": "alice@example.com"
}

TypeScript Definitions ​

Show full TypeScript definitions
ts
interface KContentInstance {
  // Each site content folder generates a matching property (folderBase for list mode, item type for single mode)
  [folderName: string]: any;
  onlineStatus(contentId: string): Record<string, boolean>;
}

interface queryOptions {
  includeOfflineData?: boolean;
  excludeEmpty?: boolean;
  take?: number;
  skip?: number;
  orderBy?: string;
  orderByDescending?: string;
  select?: string[];
}

interface contentTypeBase {
  id?: string;
  slug?: string;
  sequence?: number;
  online?: boolean;
  version?: number;
  lastModified?: string;
  creationDate?: string;
}

interface folderBase<T, M> {
  all(): T[];
  all(options: queryOptions): T[];
  get(nameOrId: string): T;
  add(content: M): T;
  update(content: M): void;
  delete(nameOrId: any): void;
  find(query: string): T;
  find(query: any): T;
  find(query: string, options: queryOptions): T;
  find(query: any, options: queryOptions): T;
  findAll(query: string): T[];
  findAll(query: any): T[];
  findAll(query: string, options: queryOptions): T[];
  findAll(query: any, options: queryOptions): T[];
  move(source: string, prev: string, next: string): T[];
}

interface RelationFolder {
  add(nameOrId: any): void;
  remove(nameOrId: any): void;
}