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
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 111 2 versions
PHP J6 J5 J3 Template Override
Custom Fields

Render Custom Fields Grouped by Field Group Conditionally

Groups all populated Custom Fields by group_title and renders them conditionally based on the active menu page class.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$active      = Factory::getApplication()->getMenu()->getActive();
// ...
52 227 2 versions
PHP J6 J5 J3 Template
Content Plugins and Languages

Detect the Active Site Language Tag

Returns the active BCP-47 language tag (such as pt-BR or en-GB) using $app->getLanguage()->getTag().

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$langTag = Factory::getApplication()->getLanguage()->getTag();
// ...
48 189 2 versions
PHP J6 J5 J3 Template
Templates and Assets

Load External JavaScript File with WebAssetManager

Registers and loads external or local JS scripts with defer via WebAssetManager to avoid render blocking.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// ...
69 277 2 versions
PHP J6 J5 J3 Template
Templates and Assets

Inject Inline CSS into the Document with WebAssetManager

Adds dynamic CSS declarations directly into <head> using addInlineStyle() with native Joomla 5/6 CSP nonce support.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// ...
39 159 2 versions
PHP J6 J5 J3 Template
Templates and Assets

Inject Inline JavaScript into the Document with WebAssetManager

Inserts inline JavaScript via addInlineScript() with automatic CSP nonce support and ordered execution.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// ...
42 167 2 versions
PHP J6 J5 J3 Plugin
Content Plugins and Languages

Trigger onContentPrepare via Helpers\Content::prepare()

Replaces removed Joomla 3 JHtmlContent::prepare() with Joomla\CMS\HTML\Helpers\Content::prepare() in Joomla 5 and 6.

<?php

declare(strict_types=1);

use Joomla\CMS\HTML\Helpers\Content;

echo Content::prepare((string) $text);
33 140 2 versions
PHP J6 J5 J3 Component
Articles and Routes

Load Filtered Articles from a Category Using ArticlesModel

Instantiates the core com_content ArticlesModel via MVCFactory with category, published state, access and limit filters.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$app     = Factory::getApplication();
// ...
39 150 2 versions
PHP J6 J5 J4 Template Override
Articles and Routes

Strip #joomlaImage:// Metadata and Read Image Dimensions

Decodes article images JSON and extracts the clean URL plus intrinsic width and height with HTMLHelper::cleanImageURL() to prevent CLS.

<?php

declare(strict_types=1);

use Joomla\CMS\HTML\HTMLHelper;

$images = json_decode((string) ($this->item->images ?? '{}'));
// ...
52 183
PHP J6 J5 J3 Template Override
Articles and Routes

Load and Render Article Tags in Overrides

Fetches tags attached to a Joomla article using TagsHelper and renders them via LayoutHelper or custom markup.

<?php

declare(strict_types=1);

use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Layout\LayoutHelper;

// ...
31 130 2 versions
PHP J6 J5 J3 Template Override
Articles and Routes

Read and Render Article Extra Links (urla, urlb, urlc)

Decodes the article urls JSON column to render structured CTA buttons such as Demo, Docs or Download inside overrides.

<?php

declare(strict_types=1);

$urls = json_decode((string) ($this->item->urls ?? '{}'));

foreach (['a', 'b', 'c'] as $slot) {
// ...
22 99 2 versions
PHP J6 J5 J3 Component
Articles and Routes

Add Custom Items to the Joomla Breadcrumb (Pathway)

Appends intermediate category links and the current item title to mod_breadcrumbs using $app->getPathway()->addItem().

<?php

declare(strict_types=1);

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

// ...
25 105 2 versions
Direct Engineering

Have a Joomla project or technical challenge in mind?

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