3

I've created a custom component with a dashboard that needs styling with CSS. I've created the CSS file and I'm looking at calling for it in the frontend view.

Working with J! 3.6.5 and a MVC developed component obviously I'm confident that I need to place the following code in an appropriate place:

JHtml::_('stylesheet', 'com_mycomponent/css/dashboard.css');

My best guess was to put it between the "public function display" lines in my "view.html.php" file. However, this does not working so I'm doing it wrong.

1 Answer 1

2

I'd suggest placing it in your view file:

components/com_mycomponent/views/VIEW_NAME/tmpl/default.php

This means that is anyone wishes to override your component views, they can, for example, remove your CSS file being referenced and use their own.

1
  • 1
    Right! That works! So is this the standard way of adding CSS files to views or is there a better way. For example if you want to add CSS that is used by multiple views?
    – Badger
    Commented Jan 13, 2017 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.