Skip to content

k.paramConfig ​

Read site-level structured settings defined and saved under Parameter Config (UserOptions) in the admin console

Execution ContextPrerequisitesTypical Use
All server-side scripts (Page, Layout, View, API, CodeBlock)Define schema and save values in Admin → Content → Parameter ConfigRead global site settings, footer links, feature flags, and metadata

k.paramConfig exposes structured site configurations maintained in the admin console to KScript, enabling non-code updates for global settings such as footer links, brand metadata, feature toggles, and navigation items with typed script access.

Quick Start ​

js
// Read the siteSettings configuration with optional chaining fallbacks
const settings = k.paramConfig.siteSettings
const siteTitle = settings?.siteTitle || "Kooboo"
const contactEmail = settings?.contact?.email || "default@example.com"

// Dynamic lookup by name
const navConfig = k.paramConfig.get("footerLinks")

Quick Reference ​

Method / PropertyDescriptionReturns
k.paramConfig.<name>Direct property access matching the configured option nameobject | undefined
k.paramConfig.get(name)Dynamic lookup by configuration name (undefined when missing)object | undefined
k.paramConfig[name]Dynamic bracket-index lookup by configuration nameobject | undefined

Read-Only Runtime Access

k.paramConfig is read-only in KScript. Both the configuration schema and saved values are managed in the admin console under Content → Parameter Config; see Admin: Parameter Config.

Access Methods ​

Read configurations directly by configuration name, via get(name), or via bracket indexing k.paramConfig[name]:

Parameter / PatternTypeRequiredDescription
namestringYes (get / bracket access)Parameter Config name configured in Admin

Returns: Saved JSON-like data matching the schema configured in Admin, or undefined if not defined or populated.

js
// Direct property access for a configuration named siteSettings
const settings = k.paramConfig.siteSettings

// Dynamic lookup by name
const navConfig = k.paramConfig.get("footerLinks")

if (settings) {
  const siteTitle = settings.siteTitle
  const enableAnnouncement = settings.showBanner
}

Data Shape and Optional Chaining ​

Each configuration returns the JSON structure matching the schema defined in the admin console (supporting strings, numbers, booleans, nested objects, and arrays), for example:

json
{
  "siteTitle": "Kooboo Docs",
  "showBanner": true,
  "contact": {
    "email": "support@example.com",
    "phone": "+86-400-000-0000"
  },
  "links": ["https://example.com/a", "https://example.com/b"]
}

Kooboo automatically generates TypeScript type definitions for each parameter configuration defined in the current site under k.paramConfig, providing autocomplete for configuration names and nested fields in the script editor. Because unpopulated configurations or optional nested objects may evaluate to undefined, guard deep accesses with optional chaining (?.) or fallback defaults:

js
const contactEmail = k.paramConfig.siteSettings?.contact?.email || "default@example.com"

Use Cases and Notes ​

  • Typical use cases: Global header/footer links, default SEO metadata, feature toggles, and public third-party identifiers editable without code deployments.
  • Caching & localization: Values are served from the site's options cache for fast template/API reads. Parameter Config does not split values by culture—use k.label for multilingual labels or k.content for localized content entries.
  • Read-only access: k.paramConfig does not persist writes at runtime; update schemas and values from the admin console.

TypeScript Definitions ​

ts
declare namespace UserOptions {
  interface KParamConfig {
    // Each saved Parameter Config item generates a matching typed property here
    // Example: siteSettings: UserOptions.$siteSettings;
    [configName: string]: any;
  }
}