Esta página aún no se ha traducido - se muestra la versión en English.

Variables & Magic Functions

Reusable {{ variables }}, and small BoxLang helper functions callable the same way.

En esta página

Variables & Magic Functions

bxsites.yaml's variables block - any shape, flat or nested - is reachable from any page as {{ dotted.path }}, resolved once at build time:

variables:
  company: Acme Corp
  supportEmail: help@acme.com
Contact {{ company }} at {{ supportEmail }}.

The current page's own frontmatter works the same way, under the reserved name page - {{ page.title }}, or {{ page.frontmatter.<key> }} for a custom field.

Magic functions

For anything a flat variable can't express, a project-wide docs/functions.bxs - plain BoxLang, no plugin/wiring needed - lets you declare small helper functions. Any function named with a leading $ becomes callable the same way, from Markdown:

function $badge( required string status ) {
    var color = status == "done" ? "success" : "warning"
    return '<span class="badge badge--' & color & '">' & encodeForHTML( status ) & '</span>'
}
Status: {{ $badge("done") }}

A magic function's own body can also bare-reference a shared context - page, siteConfig, nav, and (from the next lesson on) data - identically whether it's called from {{ }} or bare from a theme override.

Full reference, including the "reserved names" a project's own functions.bxs can't shadow: Variables & Magic Functions.

Editar esta página Descargar Markdown Última actualización Sep 11, 2026, 7:11:15 PM
Lesson 10 of 20 - Getting Started with bx-sites