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 12 of 100 snippets
XML J6 J5 J4 Template
Templates and Assets

Minimal templateDetails.xml for a Native Joomla Child Template

Declares <parent> and <inheritable>0</inheritable> so your child template inherits parent files safely across upgrades.

<?xml version="1.0" encoding="utf-8"?>
<extension type="template" client="site" method="upgrade">
    <name>cassiopeia_custom</name>
    <version>1.0.0</version>
    <creationDate>2026-11</creationDate>
    <author>Ponto Mega</author>
    <inheritable>0</inheritable>
// ...
47 167
PHP J6 J5 J4 Template
Templates and Assets

Add Font Preload and Preconnect Hints with $doc->addHeadLink()

Injects <link rel="preload"> and <link rel="preconnect"> tags cleanly into the Joomla document head to boost LCP.

<?php

declare(strict_types=1);

use Joomla\CMS\Uri\Uri;

/** @var \Joomla\CMS\Document\HtmlDocument $this */
// ...
32 124
CSS J6 J5 J4 Template
Templates and Assets

Override Bootstrap 5 CSS Variables in a Joomla Child Template

Customizes Bootstrap 5 colors, typography and corner radii cleanly using :root CSS custom properties without recompiling SCSS.

:root {
  --bs-primary: #147A3C;
  --bs-primary-rgb: 20, 122, 60;
  --bs-body-color: #12171C;
  --bs-body-bg: #FFFFFF;
  --bs-border-color: #DCE2E8;
  --bs-border-radius: 0px;
// ...
41 147
PHP J6 J5 J3 Template Override
Templates and Assets

Render a Reusable JLayout with LayoutHelper::render()

Shares UI partials (cards, badges, headers) across modules and overrides using LayoutHelper::render().

<?php

declare(strict_types=1);

use Joomla\CMS\Layout\LayoutHelper;

echo LayoutHelper::render('custom.card', [
// ...
32 128 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 112 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 138 2 versions
PHP J6 J5 Plugin
Content Plugins and Languages

Build a Native Joomla 5 and 6 Plugin with ServiceProvider and SubscriberInterface

Wires a modern plugin via DI container with SubscriberInterface and explicit typed event subscriptions.

<?php

declare(strict_types=1);

\defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
// ...
59 203
PHP J6 J5 J3 Helper / API
Content Plugins and Languages

Load a Language (.ini) File Manually and Translate with Text::_()

Loads .ini translation constants from another component, module or template so Text::_() and Text::sprintf() resolve cleanly.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;

// ...
40 145 2 versions
PHP J6 J5 J3 Helper / API
Content Plugins and Languages

Query Multilingual Item Associations with Associations::getAssociations()

Retrieves linked translations of an article or custom item to generate hreflang links or direct language switch buttons.

<?php

declare(strict_types=1);

use Joomla\CMS\Language\Associations;

$associated = Associations::getAssociations(
// ...
33 126 2 versions
PHP J6 J5 J3 Template
Content Plugins and Languages

List All Published Content Languages with LanguageHelper

Returns active content languages (lang_code, sef, title_native) to build custom switchers or hreflang markup.

<?php

declare(strict_types=1);

use Joomla\CMS\Language\LanguageHelper;

$languages = LanguageHelper::getContentLanguages([1], true, null, 'ordering', 'asc');
// ...
24 100 2 versions
Direct Engineering

Have a Joomla project or technical challenge in mind?

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