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 Override
Articles and Routes

Generate a Friendly SEF URL for a Joomla Article

Builds a canonical SEF article URL honoring category, alias and language using RouteHelper and Route::_().

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Site\Helper\RouteHelper;
// ...
86 348 2 versions
PHP J6 J5 J3 Template Override
Modules and Positions

Render Modules from Any Position Anywhere in Joomla

Loads and renders every published module assigned to a custom position inside overrides, components or templates.

<?php

declare(strict_types=1);

use Joomla\CMS\Helper\ModuleHelper;

$position = 'contato-direita';
// ...
82 324 2 versions
PHP J6 J5 J3 Template Override
Custom Fields

Render a Single Custom Field by Name in Overrides

Indexes $this->item->jcfields by field name and outputs a specific Custom Field anywhere inside a template override.

<?php

declare(strict_types=1);

// Indexa todos os campos personalizados pelo nome (machine name)
$fieldsByName = [];
foreach (($this->item->jcfields ?? []) as $field) {
// ...
97 369 2 versions
PHP J6 J5 J3 Template
Templates and Assets

Load External CSS Stylesheet with WebAssetManager

Registers and enqueues external or local CSS files into the document head using Joomla 5 and 6 WebAssetManager.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// ...
110 398 2 versions
PHP J6 J5 J3 Component
Articles and Routes

Get Category ID from an Article ID

Loads a com_content article by ID and retrieves its catid using the Joomla 5 and 6 MVCFactory or JTable in Joomla 3.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$app     = Factory::getApplication();
// ...
32 148 2 versions
PHP J6 J5 J3 Template Override
Articles and Routes

Get Current Category and Parent Category ID

Fetches a CategoryNode object and reads its parent category using the com_content category service.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$categories = Factory::getApplication()->bootComponent('com_content')->getCategory();
// ...
26 122 2 versions
PHP J6 J5 J3 Plugin
Parameters and Extensions

Read Plugin Parameters Inside the Plugin

Reads XML configuration fields inside a CMSPlugin subclass using $this->params->get() with a safe fallback.

<?php

declare(strict_types=1);

// Dentro de uma classe que estende Joomla\CMS\Plugin\CMSPlugin
$param = (string) $this->params->get('paramName', 'defaultValue');
24 111 2 versions
PHP J6 J5 J3 Helper / API
Parameters and Extensions

Read Plugin Parameters Outside the Plugin

Fetches and parses the JSON parameters of any published plugin from a module, component or template.

<?php

declare(strict_types=1);

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

// ...
39 166 2 versions
PHP J6 J5 J3 Module
Parameters and Extensions

Read Module Parameters Inside the Module

Reads module XML configuration values inside the module Dispatcher or tmpl layout files.

<?php

declare(strict_types=1);

// Dentro de tmpl/default.php ou override do módulo
/** @var \Joomla\Registry\Registry $params */
$param = (string) $params->get('paramName', 'defaultValue');
21 103 2 versions
PHP J6 J5 J3 Helper / API
Parameters and Extensions

Read Module Parameters Outside the Module

Loads a published module instance by name (and optional title) and parses its Registry parameters.

<?php

declare(strict_types=1);

use Joomla\CMS\Helper\ModuleHelper;
use Joomla\Registry\Registry;

// ...
31 135 2 versions
PHP J6 J5 J3 Component
Parameters and Extensions

Read Component Parameters Inside the Component

Retrieves active component parameters merged with current menu item overrides using $app->getParams().

<?php

declare(strict_types=1);

use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Factory;

// ...
27 120 2 versions
PHP J6 J5 J3 Helper / API
Parameters and Extensions

Read Any Component Parameters Externally

Reads global options of any component from plugins, modules, CLI scripts or other components using ComponentHelper::getParams().

<?php

declare(strict_types=1);

use Joomla\CMS\Component\ComponentHelper;

$componentParams = ComponentHelper::getParams('com_example');
// ...
29 127 2 versions
Direct Engineering

Have a Joomla project or technical challenge in mind?

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