content

Modifies the current HTML response.

Table of Contents
  1. Description
  2. Example

Description

A hook to modify the entire response body. For a regular page, it should be a HTML string. It can also be any other type of string, such as a JSON or XML string. This hook is provided by the Layout extension and will not work if you detach it.

Example

Hook::set('content', function ($content) {
    return $content . '<!-- test -->';
});

This hook will give effect to the response body that is properly passed through the route hook. If you want to apply the hook to a specific string, you can do so like this:

$content = content('.\path\to\file.html');
$content = Hook::fire('content', [$content]);

echo $content;

Other layout systems need to trigger this hook on the returned response body string to ensure that other extensions that rely on this hook will still work and affect the response body of your layout system:

$loader = new Twig\Loader\FilesystemLoader;

foreach (g(LOT . D . 'y', 0) as $k => $v) {
    if (is_file($k . D . 'index.php')) {
        $loader->addPath($k, basename($k)); // Include active layout folder(s) only!
    }
}

$twig = new Twig\Environment($loader);

echo Hook::fire('content', [$twig->render('@log/page.twig', $GLOBALS)]);

body

Modifies the body part of the current HTML response.

content

Modifies the current HTML response.

enter

Modifies the current HTTP response headers.

exit

Fires after script execution ends.

get

Fires when the application is ready.

head

Modifies the head part of the current HTML response.

let

Fires when the application finishes rendering.

set

Fires when the application is ready, before the core task is loaded.