Documentation

Interface: ModuleInterface

Full name: Clarity\ModuleInterface

Contract for Clarity engine modules.

A module bundles related filters, functions, and directives and registers them in one call via ClarityEngine::addModule().

Example

$clarity->addModule(new IntlFormatModule([
    'locale'            => 'ja_JP',
]));

Implementing a module

class MyModule implements ModuleInterface
{
    public function register(ClarityEngine $engine): void
    {
        $engine->addFilter('my_filter', fn($v) => strtoupper($v));
        $engine->addDirective('my_directive', fn($rest, $at, $expr) => '// …');
    }
}

Public methods

register() ·

public function register(Clarity\ClarityEngine $engine): void

Register all filters, functions, services, and directives that this module provides into the given engine instance.

ClarityEngine::addModule() calls this method immediately. Call addModule() before rendering templates so the module's filters and directives are available.

Parameters

Name Type Default Description
$engine ClarityEngine - The engine to register into.

Return value

  • Type: void

Back to the Index