For the complete documentation index, see llms.txt. This page is also available as Markdown.

Components

Create custom BoxLang components (tags) using BoxLang or Java

Components are BoxLang's equivalent of XML-style tags (bx:mytag). Create them in pure BoxLang or Java.

Place .bx files in your module's components/ folder. Auto-discovered at runtime.

File: components/Greet.bx

/**
 * A custom greeting component
 *
 * @attr name The name to greet (required)
 * @attr greeting The greeting prefix (default: "Hello")
 */
class {

    property name="name"     type="string";
    property name="greeting" type="string" default="Hello";

    /**
     * This method is invoked when the component is used
     * in template mode (with a body) or inline mode
     */
    function invoke(
        required any processor,
        required struct context,
        required struct attributes
    ) {
        var message = "#attributes.greeting#, #attributes.name#!";

        // Output the message
        processor.getOutputBuffer().append( message );

        // Process body content if any
        if ( !isNull( processor.getBody() ) ) {
            processor.processBody();
        }
    }
}

Usage:

Script-Style Usage

Components can also be invoked in script syntax:

Naming Convention

All components use the bx: prefix:

  • Module component named Greet<bx:greet>

  • Module component named DataTable<bx:datatable>

Component names are case-insensitive in markup.

Next Steps

  • BIFs — Create custom built-in functions

  • Interceptors — Listen to runtime events

  • Services — Global runtime services (Java only)

Last updated

Was this helpful?