Tritium Libraries (Mixers): Namespaces

A namespace is a self-contained set of functions or variables. They are most commonly found in libraries added to your project.

The default namespace for a project is the tritium namespace.

Defining a Namespace

To define a namespace, use the following:

@namespace json

Including Other Namespaces

In order to carry over functions from other namespaces, you can add those to the opening definition:

@namespace json, tritium

The above line means that when using the namespace json, the Tritium namespace will also be included. Tritium functions can then be used inside the json namespace.

Variables are not inherited in the same way: in the above example, variables defined in the tritium namespace are not available in the json namespace. This includes environment variables (e.g., $path).

Using a Namespace

To use a namespace, just use the @open function with the name of the namespace:

@open json

After that, you can use functions or variables from that namespace. The namespace will only be opened within the current scope.

Using Functions Outside of the Namespace

You can use functions outside of the namespace — just prepend the function with the namespace required.

For example, to use a json function inside the Tritium namespace:



In the example below, we:

  1. Define a namespace
  2. Write a function which will appear in the json namspace
  3. Use a function from the tritium namespace
  4. Open the json namespace to use the foo() function
  5. Close the json namespace by closing the current scope
  6. Use the foo() function outside the json namespace


@namespace json, tritium

@func foo(Text %bar) {
  log("IMPORTANT MESSAGE:" + %bar)

# ------------------------------------------------------

$("./body") {
  $("./div") {
    @open json