Skip to content

k.utils.clientJS ​

Output client-side JavaScript variables to the page

Overview ​

k.utils.clientJS injects <script> into the current HTML response and exposes the server object to the browser in the form of JSON.parse (must be in the page rendering process).

setVariable() ​

ts
const data = { firstname: "Kooboo", count: 3 }
k.utils.clientJS.setVariable("pageData", data)
// Browser output: var pageData = JSON.parse("...")
parametertypeillustrate
keystringglobal variable name
objanyJSON serializable objects

Returns: void; writes directly to the current HTML response.

monacoResource() ​

Returns the resource tag HTML fragment required by the Monaco editor for use by callback onload.

ParameterTypeRequiredDescription
callbackstringYesGlobal function name called after the Monaco main script loads

Returns: string, an HTML fragment containing <script> / <link> tags.

ts
const resources = k.utils.clientJS.monacoResource("initEditor")
k.response.write(resources)
k.response.write(`
<div id="editor"></div>
<script>
function initEditor() {
    monaco.editor.create(document.getElementById("editor"), {
        value: "console.log('Kooboo')",
        language: "javascript"
    })
}
</script>
`)

i18n() ​

Returns the current site multi-language configuration object.

ParameterTypeRequiredDescription
allbooleanNoWhether to return all language configuration

Returns: any, the current site i18n configuration object.

ts
const cfg = k.utils.clientJS.i18n()
const all = k.utils.clientJS.i18n(true)