PHP Joomla! 6 Joomla! 5 Joomla! 3 (Legacy) Template Basic

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.

Updated on 24 November 2026 39 copies 158 views
templates/seu_template/index.php
<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->addInlineStyle('
    .classe-custom {
        border-color: #D24726;
    }
');
Automatically receives Joomla 5 and 6 CSP nonces when HTTP Headers CSP is enabled.
templates/seu_template/index.php
<?php
$document = JFactory::getDocument();
$document->addStyleDeclaration('
    .classe {
        color: #12171C;
    }
');
Legacy Joomla 3 call via $document->addStyleDeclaration().

Technical explanation and best practices

Ideal for outputting dynamic CSS custom properties driven by template or module parameters. Using $wa->addInlineStyle() ensures Joomla automatically attaches the security nonce when the HTTP Headers CSP plugin is enabled.

Direct Engineering

Have a Joomla project or technical challenge in mind?

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