0

I'm trying to insert inline css in a module and it's not working.

In one of my modules php files i have the following:

$document = Factory::getDocument();

// Add styles
$style = 'body {'
    . 'background: black;'
    . 'color: rgb(0,111,51);'
    . '}';
$document->addStyleDeclaration($style);

But the whole thing is just doing nothing. I googled and found some tutorials but even when I copy their solution it's still doing nothing. Am I missing something or is this deprecated or different in joomla 4?

I would really appreciate some help. Thank you all in advance.

Edit: I tried it in multiple files and different modules but it just does nothing. Same With inline javascript and even with "$document->addStyleSheet" and "$document->addScript".

2nd Edit: I tried it in my templates index.php and its also not working there. So Either its a general problem or I'm doing something wrong. But it recognizes the "$document->addStyleDeclaration($style);" because when I forgot to define the document it told me that I cannot call addStyleDeclaration on an empty.

4
  • Please give us more detail than "one of my modules php files".
    – mickmackusa
    Jun 19 at 3:12
  • Are you sure the CSS has actually been loaded, but the specificity isn't high enough? Might be something overriding your values
    – Lodder
    Jun 19 at 7:50
  • @mickmackusa I think it's hardly important because it should work in any php file thats included somewhere in a module. But to be specific: I tried it in the tmpl/default.php and also in the [modulname].php Jun 19 at 13:51
  • @Lodder No I've checked intensively in the webviewer but it's nowhere. I even tried to add an important tag but still nothing. The style is just not coming through. Jun 19 at 13:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.