Menu

This is documentation for the next version of Alloy. For the latest stable release, go to the latest version.

Open source

Custom components

Custom components are a way to create new components from a pipeline of built-in and other custom components.

A custom component is composed of:

  • Arguments: Settings that configure the custom component.
  • Exports: Values that a custom component exposes to its consumers.
  • Components: Built-in and custom components that are run as part of the custom component.

Creating custom components

You can create a new custom component using the declare configuration block. The label of the block determines the name of the custom component.

The following custom configuration blocks can be used inside a declare block:

  • argument: Create a new named argument, whose current value can be referenced using the expression argument.NAME.value. Argument values are determined by the user of a custom component.
  • export: Expose a new named value to custom component users.

Custom components are useful for reusing a common pipeline multiple times. To learn how to share custom components across multiple files, refer to Modules.

Example

This example creates a new custom component called add, which exports the sum of two arguments:

alloy
declare "add" {
    argument "a" { }
    argument "b" { }

    export "sum" {
        value = argument.a.value + argument.b.value
    }
}

add "example" {
    a = 15
    b = 17
}

// add.example.sum == 32