Hook: before_render
avatar
Señor FAQ

¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.


Hook: before_render

The before_render hook is executed in the index.php file and runs before the template and editor are loaded. It is part of the CMS's dynamic hook system, allowing developers to extend functionality at this critical stage of rendering.

Usage


DynamicHooks::executeHook('before_render', false, $jkv, $lang);
        

This hook is triggered using the DynamicHooks::executeHook() method with the following parameters:

  • Hook Name: 'before_render' - The unique identifier for this hook.
  • Default Value: false - The default return value if no callbacks are registered.
  • Context Parameters:
    • $jkv - The configuration array containing CMS settings.
    • $lang - The active language for the CMS.

Purpose

The before_render hook allows developers to inject or modify data, execute pre-render logic, or register additional functionality right before the CMS template and editor are rendered.

Example Implementation


DynamicHooks::registerHook('before_render', function($jkv, $lang) {
    // Example: Modify a configuration option
    $jkv['custom_setting'] = 'new_value';

    // Log a message or perform actions before the template loads
    error_log("Before render hook executed for language: " . $lang);
});
        

Best Practices

  • Ensure any changes made in this hook are compatible with subsequent template rendering.
  • Avoid heavy processing to maintain fast page loading times.
  • Test callbacks thoroughly to prevent conflicts with other hooks or plugins.

Troubleshooting

  • If the hook does not execute, verify that the hook name and registration are correct.
  • Check for syntax errors or conflicts in the registered callback functions.
Was this article helpful?
0 out of 0 found this helpful