This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

rmiller63803
rmiller63803

I'm guessing this has the same answer as my last question, but I see posts here that sound like it's possible to use addCss in a backend controller. I've tried it in __construct, onStart and onRun and the css isn't included in the page. Am I missing something or is it not possible?

Thanks, Bob

daftspunky
daftspunky

Hi Bob!

It is possible. All backend controllers implement the \System\Traits\AssetMaker trait that allows calling addJs and addCss -- these should work fine when called from __construct. Although the methods onStart and onRun are typically used in front end controllers (pages, layouts).

rmiller63803
rmiller63803

Any idea why this doesn't work?

rmiller@vps67777:~/dev/vi-october$ ls -l plugins/velitalia/racescraper/assets/css/races.css
-rw-rw-r-- 1 rmiller rmiller 31 Mar  3 20:41 plugins/velitalia/racescraper/assets/css/races.css

... and ...

public function onRun() {
    $this->addCss("/plugins/velitalia/racescraper/assets/css/races.css");
}

When I view source of the page, 'races.css' doesn't appear, and a class I define there doesn't get applied, so I'm pretty sure it's not there. Does the .css file need to be somewhere else?

rmiller63803
rmiller63803

Thanks for your help. For anyone stuck on this in the future, this is what worked. For my races controller /backend/velitalia/racescraper/races/index ...

In plugins/valitalia/racescraper/controllers/Races.php:

public function index() {
    $this->addCss("/plugins/velitalia/racescraper/assets/css/races.css");
}

... and in plugins/velitalia/racescraper/controllers/races/index.htm:

<?= $this->makeAssets() ?>
daftspunky
daftspunky

Thanks for sharing your results!

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.