Technical Library / Open Source

Joomla Snippets

Searchable collection of production-ready code recipes for template overrides, modules, plugins, and Joomla! 3 to 6 APIs.

100 Snippets
12 Categories
J3 to J6 Compatibility
Showing 9 of 9 snippets
PHP J6 J5 J3 Template
Menus and Navigation

Access Parameters of the Active Menu Item

Retrieves the active MenuItem via $app->getMenu()->getActive() and reads any parameter with getParams().

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$active        = Factory::getApplication()->getMenu()->getActive();
// ...
42 174 2 versions
PHP J6 J5 J3 Template
Menus and Navigation

Access Parameters of a Menu Item by ID

Loads a specific menu item by request Itemid or known numeric ID and reads its Registry parameters.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$app      = Factory::getApplication();
// ...
28 122 2 versions
PHP J6 J5 J3 Template
Menus and Navigation

Get the Page Class Suffix (pageclass_sfx) of the Active Menu

Safely retrieves the CSS Page Class (pageclass_sfx) configured under the active menu item Display tab.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$active       = Factory::getApplication()->getMenu()->getActive();
// ...
37 155 2 versions
PHP J6 J5 J3 Template
Menus and Navigation

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.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$active      = Factory::getApplication()->getMenu()->getActive();
// ...
34 146 2 versions
PHP J6 J5 J3 Template
Menus and Navigation

Get the Alias of the Active Menu Item

Safely fetches the alias (slug) of the active menu item for CSS hooks, analytics tags or conditional layout logic.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$menuItemAlias = (string) (Factory::getApplication()->getMenu()->getActive()?->alias ?? '');
25 110 2 versions
PHP J6 J5 J3 Template
Menus and Navigation

Detect Whether the Current Page Is the Home Page (Multilingual-Safe)

Compares the active menu item against the default menu item for the active language tag via $menu->getDefault($langTag).

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$app     = Factory::getApplication();
// ...
65 227 2 versions
PHP J6 J5 J3 Module
Menus and Navigation

List Published Items from a Specific Menu by menutype

Queries top-level items of a specific menu using $app->getMenu()->getItems() with built-in ACL and language filtering.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;

// ...
28 111 2 versions
PHP J6 J5 J3 Helper / API
Menus and Navigation

Get Root URL, Current URL and Build Query Strings with Uri

Uses Joomla\CMS\Uri\Uri to read the site root, current URL and safely append query parameters.

<?php

declare(strict_types=1);

use Joomla\CMS\Uri\Uri;

$rootFull    = Uri::root();              // https://pontomega.com.br/
// ...
48 170 2 versions
PHP J6 J5 J3 Component
Menus and Navigation

Redirect with a Flash Message Using enqueueMessage() and redirect()

Queues typed system messages (success, warning, error, info) and redirects cleanly with HTTP 303 or 301 status codes.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
// ...
36 137 2 versions
Direct Engineering

Have a Joomla project or technical challenge in mind?

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