How to Load CSS file into Joomla 4 Component

2,152 views
Skip to first unread message

Glenn Arkell

unread,
Aug 18, 2020, 2:19:40 AM8/18/20
to Joomla! General Development
I'm going around in circles with trying to load my components CSS into my view tmpl without success.  Any guidance appreciated.

Tried this:
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa
->registerStyle(JPATH_SITE . '/media/com_mycomponent/mycomponent.css');  // also tried without the path
$wa
->useStyle(JPATH_SITE . '/media/com_mycomponent/mycomponent.css');

Tried this:
HTMLHelper::_('stylesheet', '/media/com_mycomponent/mycomponent.css');  // also tried with path

Tried this:
WebAssetManager::addStyleSheet(JPATH_SITE . 'media/com_mycomponent/mycomponent.css');  // also tried without path


Fedir

unread,
Aug 19, 2020, 3:16:31 AM8/19/20
to Joomla! General Development

$wa->registerStyle('bar', 'com_example/bar.css');
$wa->useStyle('bar');

or:

$wa->registerAndUseStyle('bar', 'com_example/bar.css');


вівторок, 18 серпня 2020 р. о 09:19:40 UTC+3 glenn...@gmail.com пише:

Glenn Arkell

unread,
Aug 19, 2020, 8:35:07 PM8/19/20
to Joomla! General Development
Brilliant, you are an absolute star, thank you very much for the link too.  Just shows me that I didn't look hard enough.  Much appreciated.
Reply all
Reply to author
Forward
0 new messages