class Frontend implements ExtenderInterface

Methods

__construct(string $frontend)

No description

css(string $path)

Add a CSS file to load in the frontend.

js(string $path)

Add a JavaScript file to load in the frontend.

jsDirectory(string $path)

Add a directory of JavaScript files to include in the JS assets public directory.

route(string $path, string $name, callable|string|null $content = null)

Add a route to the frontend.

removeRoute(string $name)

Remove a route from the frontend.

content(callable|string|null $callback, int $priority = 0)

Modify the content of the frontend.

preloads(callable|array $preloads)

Adds multiple asset preloads.

title(string $driverClass)

Register a new title driver to change the title of frontend documents.

extraDocumentAttributes(array $attributes)

Adds document root attributes.

extraDocumentClasses(string|array| Closure $classes)

Adds document root classes.

void
extend( Container $container, Extension|null $extension = null)

No description

Details

__construct(string $frontend)

Parameters

string $frontend : The name of the frontend.

Frontend css(string $path)

Add a CSS file to load in the frontend.

Parameters

string $path : The path to the CSS file.

Return Value

Frontend

Frontend js(string $path)

Add a JavaScript file to load in the frontend.

Parameters

string $path : The path to the JavaScript file.

Return Value

Frontend

Frontend jsDirectory(string $path)

Add a directory of JavaScript files to include in the JS assets public directory.

Primarily used to copy JS chunks.

Parameters

string $path The path to the specific frontend chunks directory.

Return Value

Frontend

Frontend route(string $path, string $name, callable|string|null $content = null)

Add a route to the frontend.

Parameters

string $path : The path of the route.
string $name : The name of the route, must be unique.
callable|string|null $content The content can be a closure or an invokable class, and should accept: - \Flarum\Frontend\Document $document - \Psr\Http\Message\ServerRequestInterface $request The callable should return void.

Return Value

Frontend

Frontend removeRoute(string $name)

Remove a route from the frontend.

This is necessary before overriding a route.

Parameters

string $name : The name of the route.

Return Value

Frontend

Frontend content(callable|string|null $callback, int $priority = 0)

Modify the content of the frontend.

Parameters

callable|string|null $callback The content can be a closure or an invokable class, and should accept: - \Flarum\Frontend\Document $document - \Psr\Http\Message\ServerRequestInterface $request The callable should return void.
int $priority : The priority of the content. Higher priorities are executed first.

Return Value

Frontend

Frontend preloads(callable|array $preloads)

Adds multiple asset preloads.

The parameter should be an array of preload arrays, or a callable that returns this. A preload array must contain keys that pertain to the `<link rel="preload">` tag. For example, the following will add preload tags for a script and font file: ``` $frontend->preloads([ [ 'href' => '/assets/my-script.js', 'as' => 'script', ], [ 'href' => '/assets/fonts/my-font.woff2', 'as' => 'font', 'type' => 'font/woff2', 'crossorigin' => '' ] ]); ```

Parameters

callable|array $preloads

Return Value

Frontend

Frontend title(string $driverClass)

Register a new title driver to change the title of frontend documents.

Parameters

string $driverClass

Return Value

Frontend

Frontend extraDocumentAttributes(array $attributes)

Adds document root attributes.

Parameters

array $attributes

Return Value

Frontend

Frontend extraDocumentClasses(string|array| Closure $classes)

Adds document root classes.

Can be a string, an array, or a Closure that returns either. An array can be of a format acceptable by the @class blade directive.

Parameters

string|array| Closure $classes

Return Value

Frontend

void extend( Container $container, Extension|null $extension = null)

Parameters

Container $container
Extension|null $extension

Return Value

void