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 13 snippets
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 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 148 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
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 276 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
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 210
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 188
XML J6 J5 J4 Template
Templates and Assets

Minimal templateDetails.xml for a Native Joomla Child Template

Declares <parent> and <inheritable>0</inheritable> so your child template inherits parent files safely across upgrades.

<?xml version="1.0" encoding="utf-8"?>
<extension type="template" client="site" method="upgrade">
    <name>cassiopeia_custom</name>
    <version>1.0.0</version>
    <creationDate>2026-11</creationDate>
    <author>Ponto Mega</author>
    <inheritable>0</inheritable>
// ...
47 166
PHP J6 J5 J4 Template
Templates and Assets

Add Font Preload and Preconnect Hints with $doc->addHeadLink()

Injects <link rel="preload"> and <link rel="preconnect"> tags cleanly into the Joomla document head to boost LCP.

<?php

declare(strict_types=1);

use Joomla\CMS\Uri\Uri;

/** @var \Joomla\CMS\Document\HtmlDocument $this */
// ...
32 124
CSS J6 J5 J4 Template
Templates and Assets

Override Bootstrap 5 CSS Variables in a Joomla Child Template

Customizes Bootstrap 5 colors, typography and corner radii cleanly using :root CSS custom properties without recompiling SCSS.

:root {
  --bs-primary: #147A3C;
  --bs-primary-rgb: 20, 122, 60;
  --bs-body-color: #12171C;
  --bs-body-bg: #FFFFFF;
  --bs-border-color: #DCE2E8;
  --bs-border-radius: 0px;
// ...
41 146
Direct Engineering

Have a Joomla project or technical challenge in mind?

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