k.page
Configure
<title>and<meta>header bindings for the page rendered by the current HTTP request
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| Scripts executed during HTML page rendering (Page, Layout, View CodeBlock) | Takes effect only on HTML template responses, not standalone JSON APIs | Dynamic SEO titles, descriptions, Open Graph tags, and charset metadata |
k.page writes header bindings into the current request's rendering context, which Kooboo outputs into <title> and <meta> during layout and page rendering. Use it to set dynamic page titles, descriptions, and Open Graph tags from request data.
Quick Start
// Page or layout CodeBlock
const productName = k.request.queryString.name || "Product"
k.page.setTitle(productName + " - Store")
k.page.setNameMeta("description", "Buy " + productName)
k.page.setPropertyMeta("og:title", productName)Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
setTitle(value) | Set or override <title> text for the current page | void |
setCharsetMeta(value) | Set document charset meta binding (ignored when empty) | void |
setNameMeta(name, content) | Set or update <meta name="..." content="..."> | void |
setPropertyMeta(property, content) | Set <meta property="..." content="..."> (Open Graph, etc.) | void |
setHttpEquivMeta(equiv, content) | Set <meta http-equiv="..." content="..."> | void |
Differences from k.site.pages and k.response.meta
| API | Purpose |
|---|---|
k.page | Current page setTitle, setNameMeta, setPropertyMeta, etc. (this page) |
k.site.pages | Create, read, update, and delete Page resources in the site; see site/page.md |
k.response.meta | Object-style access to the same header binding list (meta.title, meta.setMeta); see k.response |
k.page.setNameMeta("description", "…") and k.response.meta.setMeta("description", "…") write to the same header binding list; use whichever style fits your script. Call k.page from scripts that run during HTML page rendering—standalone API handlers that return JSON directly do not emit HTML <head> bindings.
Methods
setTitle()
Set or override the <title> text of the current page.
| Parameter | Type | Required | Description |
|---|---|---|---|
value | string | Yes | Title text |
Returns: void.
k.page.setTitle("Product Details - My Site")setCharsetMeta()
Set the document charset meta binding.
| Parameter | Type | Required | Description |
|---|---|---|---|
value | string | Yes | Charset string (ignored when empty) |
Returns: void.
k.page.setCharsetMeta("utf-8")setNameMeta()
Set <meta name="…" content="…">. Updates content if a binding with the same name already exists; otherwise appends a new binding.
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | name attribute |
content | string | Yes | content attribute |
Returns: void.
k.page.setNameMeta("description", "Site description")
k.page.setNameMeta("keywords", "kooboo, cms")setPropertyMeta()
Set <meta property="…" content="…"> (Open Graph tags, etc.).
| Parameter | Type | Required | Description |
|---|---|---|---|
property | string | Yes | property attribute |
content | string | Yes | content attribute |
Returns: void.
k.page.setPropertyMeta("og:title", "Shared title")
k.page.setPropertyMeta("og:image", "https://example.com/cover.jpg")setHttpEquivMeta()
Set <meta http-equiv="…" content="…">.
| Parameter | Type | Required | Description |
|---|---|---|---|
equiv | string | Yes | http-equiv attribute |
content | string | Yes | content attribute |
Returns: void.
k.page.setHttpEquivMeta("refresh", "30;url=/next")
k.page.setHttpEquivMeta("X-UA-Compatible", "IE=edge")TypeScript Definitions
interface KPage {
setTitle(value: string): void;
setCharsetMeta(value: string): void;
setNameMeta(name: string, content: string): void;
setPropertyMeta(property: string, content: string): void;
setHttpEquivMeta(equiv: string, content: string): void;
}Related Docs
- k.site.pages — Site page resource management
- k.response — Read and write page header bindings with
k.response.meta - k.request — Current request parameters