Search
Other Sourcerer questions
Forum

Add Print.css to Header with PHP 8.X

Marc Pradel's Avatar Marc Pradel
Hi Peter,

do you have a hint for me, how to adjust my code that it works also oh PHP 8.x

Here is the code works on PHP 7.4

{source 0}
<?php
$document->addStyleSheet('/templates/yootheme_gvr/css/print.css', 'text/css', 'print');
?>
{/source}

On PHP 8.x I get:

Cannot access offset of type string on string

because of the attributes 'text/css', 'print' I like to add.

Regards
Marc
Peter van Westen's Avatar Peter van Westen ADMIN
You can try something like this:
$doc->getWebAssetManager()->registerAndUseStyle('yootheme.print', '/templates/yootheme_gvr/css/print.css', [], ['media'  => 'print']);
Please post a rating at the Joomla! Extensions Directory
Marc Pradel's Avatar Marc Pradel
Works fine. Thank you!
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription