Some custom PHP code is run specifically on this page.
- The first part of the custom code shows the message above.
- The second part shows the server time below which is different every time you load the page.
2026-11-15 22:20:28
Below you can see, as an example, the code for the above actions.
PHP Code that runs on the Before Render event:
use Joomla\CMS\Factory;use Joomla\CMS\Date\Date;$application = Factory::getApplication();$input = Factory::getApplication()->input;$option = $input->get('option', '', 'STR');$view = $input->get('view', '', 'STR');$layout = $input->get('layout', '', 'STR');$current_time = new Date('now');
// Detect the specific page by using the page class suffix.$menu = $application->getMenu()->getActive();if (is_object($menu)) { $pageclass = $menu->getParams()->get('pageclass_sfx'); if (strpos($pageclass, 'c-add-custom-php')!==false) {// The code below runs only in the front-end. if ($application->isClient('site')) { // Show a message. $message = 'This message appears here because of the custom PHP code.'; $message .= '<br>Option: '.$option.', View: '.$view.', Layout: '.$layout; $application->enqueueMessage($message); } }}
PHP Code that runs on the After Render event:
use Joomla\CMS\Factory;use Joomla\CMS\Date\Date;$application = Factory::getApplication();$current_time = new Date('now');
// Detect the specific page by using the page class suffix.$menu = $application->getMenu()->getActive();if (is_object($menu)) { $pageclass = $menu->getParams()->get('pageclass_sfx'); if (strpos($pageclass, 'c-add-custom-php')!==false) {// The code below runs only in the front-end. if ($application->isClient('site')) { // Manipulate the body of the page... $body = $application->getBody(); $body = str_replace('2026-11-15 22:20:28', $current_time, $body); $application->setBody($body); } }}