Skip to content

k.page ​

Configure <title> and <meta> header bindings for the page rendered by the current HTTP request

Execution ContextPrerequisitesTypical Use
Scripts executed during HTML page rendering (Page, Layout, View CodeBlock)Takes effect only on HTML template responses, not standalone JSON APIsDynamic 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 ​

js
// 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 / PropertyDescriptionReturns
setTitle(value)Set or override <title> text for the current pagevoid
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

APIPurpose
k.pageCurrent page setTitle, setNameMeta, setPropertyMeta, etc. (this page)
k.site.pagesCreate, read, update, and delete Page resources in the site; see site/page.md
k.response.metaObject-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.

ParameterTypeRequiredDescription
valuestringYesTitle text

Returns: void.

js
k.page.setTitle("Product Details - My Site")

setCharsetMeta() ​

Set the document charset meta binding.

ParameterTypeRequiredDescription
valuestringYesCharset string (ignored when empty)

Returns: void.

js
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.

ParameterTypeRequiredDescription
namestringYesname attribute
contentstringYescontent attribute

Returns: void.

js
k.page.setNameMeta("description", "Site description")
k.page.setNameMeta("keywords", "kooboo, cms")

setPropertyMeta() ​

Set <meta property="…" content="…"> (Open Graph tags, etc.).

ParameterTypeRequiredDescription
propertystringYesproperty attribute
contentstringYescontent attribute

Returns: void.

js
k.page.setPropertyMeta("og:title", "Shared title")
k.page.setPropertyMeta("og:image", "https://example.com/cover.jpg")

setHttpEquivMeta() ​

Set <meta http-equiv="…" content="…">.

ParameterTypeRequiredDescription
equivstringYeshttp-equiv attribute
contentstringYescontent attribute

Returns: void.

js
k.page.setHttpEquivMeta("refresh", "30;url=/next")
k.page.setHttpEquivMeta("X-UA-Compatible", "IE=edge")

TypeScript Definitions ​

ts
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;
}
  • k.site.pages — Site page resource management
  • k.response — Read and write page header bindings with k.response.meta
  • k.request — Current request parameters