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
Modules and Positions

Check Published Modules in Positions with countModules()

Dynamically calculates Bootstrap 5 main and sidebar column widths based on active modules in sidebar-left and sidebar-right.

<?php

declare(strict_types=1);

$hasLeft  = $this->countModules('sidebar-left', true) > 0;
$hasRight = $this->countModules('sidebar-right', true) > 0;
$mainCol  = ($hasLeft && $hasRight) ? 'col-lg-6' : (($hasLeft || $hasRight) ? 'col-lg-9' : 'col-12');
// ...
46 172 2 versions
PHP J6 J5 Module
Modules and Positions

Create Modern services/provider.php for a Joomla 5 and 6 Module

Registers ModuleDispatcherFactory, HelperFactory and the Module service via the DI Container without a legacy mod_example.php entry file.

<?php

declare(strict_types=1);

\defined('_JEXEC') or die;

use Joomla\CMS\Extension\Service\Provider\HelperFactory;
// ...
58 193
PHP J6 J5 Module
Modules and Positions

Create a Modern Module Dispatcher Extending AbstractModuleDispatcher

Implements getLayoutData() with HelperFactoryAwareTrait to inject clean data into module tmpl layouts.

<?php

declare(strict_types=1);

namespace Vendor\Module\Example\Site\Dispatcher;

\defined('_JEXEC') or die;
// ...
52 176
PHP J6 J5 J3 Template Override
Modules and Positions

Render a Specific Module by Type and Title via ModuleHelper

Loads and renders a single module instance by module name (e.g. mod_finder) and exact title regardless of position.

<?php

declare(strict_types=1);

use Joomla\CMS\Helper\ModuleHelper;

$module = ModuleHelper::getModule('mod_finder', 'Busca Global');
// ...
29 120 2 versions
PHP J6 J5 J4 Template
Modules and Positions

Create a Custom Module Chrome in html/layouts/chromes/

Defines a reusable Joomla 4, 5 and 6 module chrome layout replacing legacy html/modules.php functions.

<?php

declare(strict_types=1);

\defined('_JEXEC') or die;

$module  = $displayData['module'];
// ...
36 142
PHP J6 J5 J3 Helper / API
Custom Fields

Load Custom Fields Outside Article View with FieldsHelper::getFields()

Retrieves prepared Custom Fields for any article inside modules, plugins or custom components using FieldsHelper::getFields().

<?php

declare(strict_types=1);

use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;

$fields = FieldsHelper::getFields('com_content.article', $item, true);
// ...
57 205 2 versions
PHP J6 J5 J4 Template Override
Custom Fields

Render a Repeatable Subform Custom Field in Overrides

Iterates over $field->subform_rows on a Joomla Subform Custom Field to build FAQs, spec tables or feature grids.

<?php

declare(strict_types=1);

$fieldsByName = [];
foreach (($this->item->jcfields ?? []) as $f) {
    $fieldsByName[$f->name] = $f;
// ...
62 216
PHP J6 J5 J3 Template Override
Custom Fields

Use Raw Value (rawvalue) vs Formatted Value (value) in Custom Fields

Uses rawvalue for conditionals, URLs and data attributes while keeping value for human-readable formatted output.

<?php

declare(strict_types=1);

use Joomla\CMS\HTML\HTMLHelper;

// Campo tipo List: rawvalue = chave ('em-andamento'), value = rótulo ('Em andamento')
// ...
34 135 2 versions
PHP J6 J5 Template Override
Custom Fields

Load Custom Fields Attached to a Category (com_content.categories)

Fetches Custom Fields assigned to article categories for hero banners, subtitles or extra archive metadata.

<?php

declare(strict_types=1);

use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;

$catFields = FieldsHelper::getFields('com_content.categories', $this->category, true);
// ...
27 111
PHP J6 J5 Template Override
Custom Fields

Load Author Custom Fields (com_users.user) for an Author Bio Box

Loads the article author via UserFactoryInterface and reads their com_users.user Custom Fields such as role, bio and avatar.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
// ...
30 118
JSON J6 J5 J4 Template
Templates and Assets

Register Modular CSS and JavaScript in joomla.asset.json

Declarative WebAssetManager manifest defining styles, deferred scripts, dependencies and a single reusable preset.

{
  "$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
  "name": "meu_tema",
  "version": "1.0.0",
  "license": "GPL-2.0-or-later",
  "assets": [
    {
// ...
62 211
PHP J6 J5 J4 Template
Templates and Assets

Load Bootstrap 5 JavaScript Modules On Demand via WebAssetManager

Enqueues only the specific Bootstrap 5 JS components needed (collapse, dropdown, modal, offcanvas) instead of the full bundle.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// ...
55 189
Direct Engineering

Have a Joomla project or technical challenge in mind?

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