{%- extends "theming/base.html" -%} {%- block subtitle -%} {{- ui.subtitle_item(util) if util }} {{- ui.subtitle_item("JavaScript") }} {{- super() }} {%- endblock %} {%- block breadcrumb_content -%} {{ super() }} {{- ui.breadcrumb(_("JavaScript"), href=h.url_for("theming.js"), active=not util) }} {{- ui.breadcrumb(util, href=h.url_for("theming.js", util=util), active=true) if util }} {%- endblock %} {%- block content_primary_nav -%} {{ ui.content_nav_item("Overview", href=h.url_for("theming.js"), active=request.endpoint == "theming.js") }} {%- endblock %} {%- block secondary_content -%} {{ super() }} {%- if available_utils -%} {%- call ui.util.call(ui.sidebar_nav, title=_("JS Utilities")) -%} {%- for name in available_utils -%} {{ ui.sidebar_nav_item(name, href=h.url_for("theming.js", util=name), active=util==name) }} {%- endfor %} {%- endcall %} {%- endif %} {%- endblock %} {%- block primary_content_inner -%} {%- macro show_example(content, language, escape=false, scope={}) -%} Code:
{{ ui.code(content|forceescape, language=language, dedent=true) }}
Result:
{{ content | render_string(scope) |safe}}
{%- endmacro %} {%- if util -%} {%- include "theming/js/" ~ util ~ ".html" -%} {%- else -%}

JavaScript utilities

Theming extension registers a set of JS functions inside Sandbox object. To access them, initialize Sandbox and use its ui attribute. Inside data-modules Sandbox object is available as this.sandbox: {%- call ui.util.call(ui.code, language="javascript", dedent=true) %} // outside of a data-module const sandbox = ckan.sandbox() const btn = sandbox.ui.button() // inside the data module ckan.module("...", function() {   return {     initialize() {         const btn = this.sandbox.ui.button()     }   } }) {%- endcall %}

{%- endif %} {%- endblock %}