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 8 of 8 snippets
PHP J6 J5 J3 Component
DI Architecture, MVC and API

Return Standardized JSON Responses in AJAX Endpoints with JsonResponse

Outputs structured {success, message, data} JSON payloads with proper Content-Type headers and clean $app->close() termination.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Response\JsonResponse;

// ...
56 194 2 versions
PHP J6 J5 J3 Helper / API
DI Architecture, MVC and API

Store and Read Native Cache via CacheControllerFactoryInterface

Caches expensive computations or external API responses using Joomla native cache handlers (File, Redis, APCu).

<?php

declare(strict_types=1);

use Joomla\CMS\Cache\CacheControllerFactoryInterface;
use Joomla\CMS\Factory;

// ...
47 165 2 versions
PHP J6 J5 J3 Helper / API
DI Architecture, MVC and API

Write Structured Logs to administrator/logs/ with Log::addLogger()

Creates a dedicated _JEXEC-protected .php log file to audit webhooks, API sync jobs and background errors.

<?php

declare(strict_types=1);

use Joomla\CMS\Log\Log;

Log::addLogger(
// ...
36 134 2 versions
PHP J6 J5 J3 Helper / API
DI Architecture, MVC and API

Send Transactional Emails with MailerFactoryInterface in Joomla 5 and 6

Creates an isolated configured mailer (SMTP/Sendmail) via MailerFactoryInterface replacing deprecated Factory::getMailer().

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Mail\MailerFactoryInterface;

// ...
59 199 2 versions
PHP J6 J5 J3 Helper / API
DI Architecture, MVC and API

Make External HTTP Requests with HttpFactory::getHttp()

Consumes external REST APIs with timeouts, Bearer headers and status checks using Joomla native HTTP client.

<?php

declare(strict_types=1);

use Joomla\CMS\Http\HttpFactory;

$http     = HttpFactory::getHttp();
// ...
41 147 2 versions
PHP J6 J5 J3 Helper / API
DI Architecture, MVC and API

Work with Files and Folders Using Joomla\Filesystem\File and Folder

Replaces removed JFile, JFolder and Joomla\CMS\Filesystem classes with the Joomla\Filesystem Framework package in Joomla 5 and 6.

<?php

declare(strict_types=1);

use Joomla\Filesystem\File;
use Joomla\Filesystem\Folder;
use Joomla\Filesystem\Path;
// ...
49 170 2 versions
XML J6 J5 J4 Component
DI Architecture, MVC and API

Define a Repeatable Subform and Conditional showon Fields in XML

Combines a switcher toggle, zero-JS showon conditional visibility and a draggable multiple subform in Joomla XML forms.

<?xml version="1.0" encoding="utf-8"?>
<form>
    <fieldset name="options" label="COM_EXAMPLE_OPTIONS">
        <field name="enable_blocks" type="radio"
               layout="joomla.form.field.radio.switcher"
               label="COM_EXAMPLE_ENABLE_BLOCKS" default="0">
            <option value="0">JNO</option>
// ...
46 161
Bash / CLI J6 J5 J4 CLI
DI Architecture, MVC and API

Consume the Native Joomla REST API (/api/index.php/v1) with Token Auth

Lists and creates articles through Joomla Web Services API v1 using X-Joomla-Token authentication and JSON:API payloads.

# Defina o token em variável de ambiente
export JOOMLA_API_TOKEN="seu_token_aqui"

# 1) Listar artigos publicados (GET)
curl -sS -X GET "https://seusite.com.br/api/index.php/v1/content/articles?page[limit]=5" \
  -H "Accept: application/vnd.api+json" \
  -H "X-Joomla-Token: ${JOOMLA_API_TOKEN}"
// ...
53 181
Direct Engineering

Have a Joomla project or technical challenge in mind?

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