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
Templates and Assets

Read Template Parameters Inside the Template

Directly reads configuration fields from the active template style inside index.php or component.php.

<?php

declare(strict_types=1);

// Dentro de templates/<seu_template>/index.php
/** @var \Joomla\CMS\Document\HtmlDocument $this */
$param = (string) $this->params->get('paramName', 'defaultValue');
23 107 2 versions
PHP J6 J5 J3 Template Override
Templates and Assets

Read Active Template Parameters Outside the Template

Fetches the active template object (including params and parent) inside component overrides, modules or plugins.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$template = Factory::getApplication()->getTemplate(true);
// ...
34 149 2 versions
PHP J6 J5 J3 Template Override
Articles and Routes

Extract the First Image from Article Content

Finds the first <img> tag inside introtext or fulltext as a safe fallback when no structured intro image is set.

<?php

declare(strict_types=1);

use Joomla\CMS\HTML\HTMLHelper;

$images = json_decode((string) ($item->images ?? '{}'));
// ...
45 186 2 versions
PHP J6 J5 J3 Template
Templates and Assets

Get the Active Template Base Path

Builds the clean relative URL for the active template directory and its modern /media/templates/site/ folder.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;

// ...
28 124 2 versions
PHP J6 J5 J3 Template Override
Articles and Routes

Truncate and Strip HTML from Article Text Safely

Strips HTML tags, normalizes whitespace and truncates UTF-8 text on word boundaries using core HTMLHelper string.truncate.

<?php

declare(strict_types=1);

use Joomla\CMS\HTML\HTMLHelper;

$maxLimit = 200;
// ...
54 220 2 versions
PHP J6 J5 J3 Template Override
Articles and Routes

Generate Friendly SEF URL for an Article Category

Generates the SEF URL for an article category using RouteHelper::getCategoryRoute() and Route::_().

<?php

declare(strict_types=1);

use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Site\Helper\RouteHelper;

// ...
33 137 2 versions
PHP J6 J5 J3 Plugin
Parameters and Extensions

Check if a Content Plugin Is Enabled and Read Its Options

Checks whether a specific content plugin is published before safely reading its Registry parameters.

<?php

declare(strict_types=1);

use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Registry\Registry;

// ...
20 98 2 versions
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 156 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 Override
Content Plugins and Languages

Process Content Plugins (content.prepare) on Custom Text

Evaluates shortcodes such as {loadposition}, {loadmodule} and content plugins on arbitrary text from custom components or database queries.

<?php

declare(strict_types=1);

use Joomla\CMS\HTML\HTMLHelper;

// Aplica todos os plugins do grupo "content" ao texto informado
// ...
50 201 2 versions
Direct Engineering

Have a Joomla project or technical challenge in mind?

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