4

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.

3

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
    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 Jan 13 '17 at 12:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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