> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-framework/module-development/capabilities/components.md).

# Components

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

{% tabs %}
{% tab title="🟦 BoxLang Components" %}
Place `.bx` files in your module's `components/` folder. Auto-discovered at runtime.

**File:** `components/Greet.bx`

```js
/**
 * 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:**

```xml
<bx:greet name="World" greeting="Hi" />
<bx:greet name="World">
    <p>Additional content here</p>
</bx:greet>
```

{% endtab %}

{% tab title="☕ Java Components" %}
Extend `Component` and annotate with `@BoxComponent`. Registered via ServiceLoader.

**File:** `src/main/java/ortus/boxlang/modules/mymodule/components/Greet.java`

```java
import ortus.boxlang.runtime.components.Attribute;
import ortus.boxlang.runtime.components.BoxComponent;
import ortus.boxlang.runtime.components.Component;
import ortus.boxlang.runtime.components.Component.BodyResult;
import ortus.boxlang.runtime.context.IBoxContext;
import ortus.boxlang.runtime.scopes.Key;
import ortus.boxlang.runtime.types.IStruct;

@BoxComponent
public class Greet extends Component {

    public Greet() {
        declaredAttributes = new Attribute[] {
            new Attribute( Key.name, "string" ),
            new Attribute( Key.greeting, "string", "Hello" )
        };
    }

    @Override
    public BodyResult _invoke(
        IBoxContext context,
        IStruct attributes,
        ComponentBodyProxy body,
        IStruct data
    ) {
        String name     = attributes.getAsString( Key.name );
        String greeting = attributes.getAsString( Key.greeting );

        print( context, greeting + ", " + name + "!" );

        return processBody( context, body );
    }
}
```

**ServiceLoader Config:** `META-INF/services/ortus.boxlang.runtime.components.Component`

```
ortus.boxlang.modules.mymodule.components.Greet
```

{% endtab %}
{% endtabs %}

## Script-Style Usage

Components can also be invoked in script syntax:

```js
bx:greet name="World" greeting="Hi"

// With a body block
bx:greet name="World" {
    writeOutput( "<p>Extra content</p>" )
}
```

## 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](/boxlang-framework/module-development/capabilities/bifs.md) — Create custom built-in functions
* [Interceptors](/boxlang-framework/module-development/capabilities/interceptors.md) — Listen to runtime events
* [Services](/boxlang-framework/module-development/capabilities/services.md) — Global runtime services (Java only)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-framework/module-development/capabilities/components.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
