addHeaderItem from package controller on_start
PermalinkUnfortunately, I'm stuck adding the css file to the header. I've poked around the forums and google search and found a few resources. Most notably this one:
http://www.concrete5.org/community/forums/customizing_c5/loading-ex...
Although, I'm not able to get this working. The css file is contained in /package_name/css/ and the current code I'm trying to use is as follows:
public function on_start() { $html = Loader::helper('html'); $this->addHeaderItem($html->css('animationcss.css','enlil_animations')); }
Any assistance would be much appreciated!
public function on_start() { $html = Loader::helper('html'); $view = View::getInstance(); $view->addHeaderItem($html->css('animationcss.css','enlil_animations')); }
Time to make some custom templates :)
Also there were some issues with code directly in on_start with core upgrades. If this is going in an addon that is compatible before 5.6.2.1, you should check what you have does not allow the c5 upgrade bug to manifest.
The situation for individual page type controllers (such as dashboard single pages) is different, because the on_start handler in page controllers is only run when that page is loaded.
The idea here is the css will be loaded not only for the package, but also for developers to use anywhere within code, and works well. If someone wants to hack their dashboard pages and add classes to their elements that's on them :)
I've done some testing in 5.6.1.2 in dashboard pages, etc. and everything is looking good so far.
http://www.concrete5.org/developers/bugs/5-6-2-1/event-handlers-dur...
Its just not good practice to load stuff like extra js or css globally across the dashboard. If a developer wants to create a dashboard single page to use it, they can explicitly load as and when they need it in their own single page controller. So your package should only load for front-end pages.
So - some examples of the sort of things you can do with on_before_render that you can't do wit on_start (not sure that all this is quite correct, but it will give you the idea):
function on_before_render(){ $page = Page::getCurrentPage() if(!is_object($page) || $page->isError()){ return; } if($page->isSystemPage()){ return; } if($page->isEditMode()){ return; } $path=$page->getCollectionPath(); if(strpos($path, '/dashboard/') !== false){ return; }
on_before_render is not called until the page is known, so you can use tests on the page and path within the handler to filter out including the css for dashboard pages or other pages where it isn't wanted.