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 11 of 11 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 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 147 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 121 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 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 221 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 138 2 versions
PHP J6 J5 J3 Component
Articles and Routes

Load Filtered Articles from a Category Using ArticlesModel

Instantiates the core com_content ArticlesModel via MVCFactory with category, published state, access and limit filters.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$app     = Factory::getApplication();
// ...
39 150 2 versions
PHP J6 J5 J4 Template Override
Articles and Routes

Strip #joomlaImage:// Metadata and Read Image Dimensions

Decodes article images JSON and extracts the clean URL plus intrinsic width and height with HTMLHelper::cleanImageURL() to prevent CLS.

<?php

declare(strict_types=1);

use Joomla\CMS\HTML\HTMLHelper;

$images = json_decode((string) ($this->item->images ?? '{}'));
// ...
52 183
PHP J6 J5 J3 Template Override
Articles and Routes

Load and Render Article Tags in Overrides

Fetches tags attached to a Joomla article using TagsHelper and renders them via LayoutHelper or custom markup.

<?php

declare(strict_types=1);

use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Layout\LayoutHelper;

// ...
31 130 2 versions
PHP J6 J5 J3 Template Override
Articles and Routes

Read and Render Article Extra Links (urla, urlb, urlc)

Decodes the article urls JSON column to render structured CTA buttons such as Demo, Docs or Download inside overrides.

<?php

declare(strict_types=1);

$urls = json_decode((string) ($this->item->urls ?? '{}'));

foreach (['a', 'b', 'c'] as $slot) {
// ...
22 98 2 versions
PHP J6 J5 J3 Component
Articles and Routes

Add Custom Items to the Joomla Breadcrumb (Pathway)

Appends intermediate category links and the current item title to mod_breadcrumbs using $app->getPathway()->addItem().

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;

// ...
25 105 2 versions
Direct Engineering

Have a Joomla project or technical challenge in mind?

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