k.content
Query, create, update, delete, reorder, relate, and localize Kooboo ContentFolders and TextContent items
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| All server-side scripts (API, View, Page, Layout, Jobs) | Create ContentTypes and Content Folders in Admin first | Fetching 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
// 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) : nullQuick Reference
| Method / Property | Description | Returns |
|---|---|---|
k.content.<folderName> | Access list-folder operations or the single item on Single-Content folders | folderBase<T, M> / T | null |
onlineStatus(contentId) | Get per-culture online status flags for an item | Record<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 userKey | T | null |
<folder>.add(content) | Create a new item in the folder and return it | T |
<folder>.update(content) | Persist edits to an existing item | void |
<folder>.delete(nameOrId) | Delete an item by object, id, or userKey | void |
<folder>.find(query, options?) | Return the first item matching a condition string or filter object | T | null |
<folder>.findAll(query, options?) | Return all items matching a condition string or filter object | T[] |
<folder>.findAllByCategory(folder, slugOrId, options?) | Fetch items linked to a specific category item | T[] |
<folder>.move(source, prev?, next?) | Reorder an item relative to adjacent items | void |
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:
// 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).
// 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
contentId | string | Yes | Content item id or userKey |
Returns: Record<string, boolean> mapping each culture code to its online flag.
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).
| Parameter | Type | Required | Description |
|---|---|---|---|
options | QueryOptions | No | Optional pagination, sorting, filtering, and field projection options |
Returns: Array of content items T[].
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
nameOrId | string | Yes | Content 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.
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
content | object | Yes | Custom content-type fields plus optional built-in system fields |
Returns: The newly created content item T.
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
content | KTextContent | Yes | Must be a KTextContent object returned by get(), find(), all(), or add(); plain JS object literals are silently ignored |
Returns: void.
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
nameOrId | any | Yes | Content object, id, or userKey |
Returns: void.
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 itemT(takefixed to1), ornullif none match.findAll(query, options?): Returns all matching itemsT[].
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | object | Yes | String query expression or filter object |
options | QueryOptions | No | Pagination, sorting, and filtering options |
Returns: find() returns T | null; findAll() returns T[].
// 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).
| Parameter | Type | Required | Description |
|---|---|---|---|
categoryFolder | string | Yes | Actual category ContentFolder name or folder ID (does not resolve relation aliases; passing an alias that differs from the folder name silently returns []) |
categorySlugOrId | string | Yes | Category item id, slug, or userKey |
options | QueryOptions | No | Sorting, 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).
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
source | string | Yes | id of the item to move |
prev | string | null | No | id of the item that should precede source (pass null to place first) |
next | string | null | No | id 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).
// 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
| Operator | Meaning | Example |
|---|---|---|
== / = | Equal | "status == 'published'" |
!= / <> | Not equal | "status != 'draft'" |
> / >= / < / <= | Numeric or date comparison | "sequence >= 10" |
contains | Substring match | "title contains 'Kooboo'" |
startwith | Prefix match (spelled without s) | "username startwith 'dev'" |
&& / and | Logical AND | "online == true && views > 100" |
|| / or | Logical 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 Key | Meaning | Example |
|---|---|---|
$eq | Equal | { views: { $eq: 100 } } |
$ne | Not equal | { status: { $ne: 'archived' } } |
$gt / $gte | Greater than / Greater than or equal | { creationDate: { $gte: '2026-01-01T00:00:00Z' } } |
$lt / $lte | Less than / Less than or equal | { sequence: { $lte: 50 } } |
$startswith | Prefix match (alias $startwith) | { username: { $startswith: 'user_' } } |
$contains | Substring match (alias $contain) | { title: { $contains: 'API' } } |
$and | Logical AND array | { $and: [{ online: true }, { sequence: { $gt: 0 } }] } |
$or | Logical OR array | { $or: [{ tag: 'a' }, { tag: 'b' }] } |
Query Options (QueryOptions)
| Option | Type | Default | Description |
|---|---|---|---|
includeOfflineData | boolean | false | Include offline/unpublished items (alias includeOffline) |
excludeEmpty | boolean | false | On multilingual sites, exclude items whose multilingual fields are empty in the active culture |
take | number | 999 (10 in findAllByCategory) | Maximum number of items to return (all() / findAll() default to 999; findAllByCategory() defaults to 10 unless take is passed explicitly) |
skip | number | 0 | Number of items to skip for pagination |
orderBy | string | — | Field name for ascending sort |
orderByDescending | string | — | Field name for descending sort |
select | string[] | — | Limit retrieved custom fields (system fields remain present) to improve query performance |
const pageItems = k.content.Blog.all({
includeOfflineData: false,
excludeEmpty: true,
orderByDescending: "creationDate",
skip: 10,
take: 10,
select: ["title", "created", "tags"]
})Related Content (relatedContent)
When Category or Embedded folder relations are configured on a folder in the admin console, read and mutate relationships as follows:
- 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.
- Add or remove links: Use
item.relatedContent.<RelationName>.add(targetOrId)and.remove(targetOrId)(pass the target item object,id, oruserKey).
// 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:
// 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:
| Field | Type | Description |
|---|---|---|
id | string | Unique content identifier (GUID) |
userKey | string | User-defined or system-generated unique key |
slug | string | URL-friendly slug (can be passed in add() or generated by Kooboo) |
sequence | number | Sort order number |
online | boolean | Online status flag |
creationDate | string | Creation timestamp (ISO 8601 string) |
lastModified | string | Last modification timestamp (ISO 8601 string) |
folderId | string | Parent content folder ID |
contentTypeId | string | Content type ID |
enableAvailableDate | boolean | Whether scheduled availability dates are enabled |
availableStartDate | string | null | Scheduled start date |
availableEndDate | string | null | Scheduled end date |
parentId | string | null | Not exposed on TextContentCultureView / KTextContent; always reads as null via k.content |
version | number | null | Not exposed on TextContentCultureView / KTextContent; always reads as null via k.content |
Example JSON output:
{
"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
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;
}