Appearance
k-data
Declare data flow with HTML tags inside a template. This is the recommended approach and replaces deprecated
k-query.
Overview
k-data uses plain HTML tags such as <k-data>, <let>, and <query> to describe a full server-side data flow: read request values, query data, shape the result, and expose variables. Add the export attribute to the <query> or <let> that creates a value needed by the template.
Compared with the old single-attribute k-query syntax, k-data:
- has a fixed structure that is easier for AI generation and code review,
- supports branches, exceptions, redirects, and field mapping,
- and uses JSON5 conditions for
whereandtestinstead of SQL-like strings.
Division of responsibility with template bindings
| Layer | Syntax | Responsibility |
|---|---|---|
Inside <k-data> | <let>, <query>, <when> and friends | Prepare data |
| Template DOM | k-content, k-for, k-if, k-attribute | Render UI |
See Template Binding Syntax for the rendering layer.
Minimal Runnable Example
This example does one thing: query article content and display each title.
html
<k-data>
<query
as="articles"
source="content"
resource="article"
action="list"
export
></query>
</k-data>
<ul>
<li k-for="article in articles">
<span k-content="article.title"></span>
</li>
</ul>This is the smallest complete data flow:
<query>fetches data and stores the result inarticles.- The
exportattribute on<query>exposesarticlesto the template. k-foriterates over the result andk-contentdisplays each title.
Before you run it
The site must have a Content Folder named article with a title field. Replace these names with the resource and field names used by your site.
Related Topics
| Topic | Description | Documentation |
|---|---|---|
| Fields and filters | Control query results with select and where | Query Sources |
| Request input | Read values from URLs, cookies, headers, and other request sources | Tag Syntax · let |
| Pagination and sorting | Use paged, page-number, and order-desc | Query Sources · paged |
| Mapping and formatting | Reshape fields and format display values | Tag Syntax · map, Built-in Functions |
| Conditions and errors | Branches, error handling, and redirects | Condition Expressions, Tag Syntax |
Authoring Conventions
- Read external input with
sourceplusfrom, such asqueryStringorcookie. - Use
source,resource, andactionfor queries. Standardize pagination withpage-numberandpage-size. - For
action="paged", map the list withfrom="result.list". - In the template layer, use only variables exposed with the
exportattribute. <when>,<else-if>, and<else>belong only inside<k-data>. In the DOM layer, usek-if,k-else-if, andk-else.- The
{...}syntax ink-attributeonly interpolates variables. It does not perform calculations. Use<let use="add|subtract|...">first, then bind the result. <query>is not an HTML void element. Always include</query>; do not write<query ... />.
Tag Summary
| Tag | Responsibility |
|---|---|
k-data | Root container for the data flow |
let | Variables, request input, or built-in function calls |
query | Query content, commerce, database, and related sources |
map | Map over an array or object |
when / else-if / else | Conditional branches inside k-data |
try / catch | Exception handling |
redirect | Server-side redirect |
export is a boolean attribute on <query> and <let> that exposes their as variable to the template layer.
See Tag Syntax for details.
Docs in This Section
| Topic | Description |
|---|---|
| Tag Syntax | let, query, map, branching, and exposing variables |
| Query Sources | content, commerce, sqlite, mysql, culture, and more |
| Built-in Functions | dateFormat, jwtDecode, math, and text helpers |
| Condition Expressions | JSON5 where and test syntax |
Relationship to KScript APIs
| Scenario | Doc |
|---|---|
| Declarative data fetching inside a template | This k-data section |
| CRUD or business logic in script code | k.content, k.DB, k.commerce and related APIs |