PHP Joomla! 6 Joomla! 5 Joomla! 3 (Legacy) Template Basic

Run Conditional Code Based on the Menu Page Class

Splits pageclass_sfx into an array of classes and checks with strict in_array() whether a target class is active.

Updated on 24 November 2026 34 copies 145 views
templates/seu_template/index.php
<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$active      = Factory::getApplication()->getMenu()->getActive();
$rawClasses  = $active ? trim((string) $active->getParams()->get('pageclass_sfx', '')) : '';
$pageClasses = $rawClasses !== '' ? (preg_split('/\s+/', $rawClasses) ?: []) : [];
?>
<?php if (\in_array('minha-classe', $pageClasses, true)) : ?>
    <!-- Bloco exibido apenas quando a classe está ativa -->
<?php endif; ?>
Splits on any whitespace and uses strict in_array() comparison.
templates/seu_template/index.php
<?php
$tuaclasse = explode(' ', JFactory::getApplication()->getMenu()->getActive()->params->get('pageclass_sfx'));
?>
<?php if (in_array('troque-pelo-nome-da-classe', $tuaclasse)) : ?>
    <!-- restante do código -->
<?php endif; ?>
Classic Joomla 3 implementation using explode() and in_array().

Technical explanation and best practices

Lets you conditionally render markup, sidebars or specialized components only on pages tagged with a specific Page Class in Menu Manager.

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.