Include asset file to the active theme via a dashboard page

Permalink
Hi,
What would be best way to include an asset file (css, js) to active theme via a dashboard page? I was thinking about hooking into events, tracking code field,..
Any idea on this?
Edit: Editing theme files is not considered, i want that all handled inside my package.

 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi Sepehr,

In the theme page_theme.php and theme files, you could conditionally include assets based on config values. In your dashboard page, you could include a form to set and changes these config values (processed by the dashboard page controller).

You can also use config values in your theme package controller with events.

I am working on some documentation on using configuration, but in the meantime you can look at this package code to see examples of what I describe.
http://www.concrete5.org/marketplace/addons/mrkdilkington-customize...

For conditionally including the assets in your theme, you can take a look at the example in this discussion:
https://www.concrete5.org/community/forums/5-7-discussion/jquery-in-...
- Instead of checking for the toolbar or loggedin, you would use the config values.
Herkool replied on at Permalink Reply
ThanX for the answer, but i don't want to edit theme files (it should all handled inside my package)
MrKDilkington replied on at Permalink Reply
MrKDilkington
@Sepehr

In your package controller on_start() method, you could try conditionally adding the assets based on a config values using addFooterItem() and addHeaderItem(). Additional checks would be needed to limit what pages the assets were added to, like isAdminArea(), isLoggedIn(), and canViewToolbar().
Herkool replied on at Permalink Reply
With adding that to package main controller on_start method
public function on_start() {
    $this->addFooterItem('/packages/my_package/css/test1.css');
}
I get this error:
Fatal error: Call to undefined method MyPackagePackage::addFooterItem()
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
@Sepehr

You can try this:
public function on_start()
{
    $v = \View::getInstance();
    $v->addHeaderItem('<link href="' . DIR_REL . '/packages/my_package/css/test1.css" rel="stylesheet">');
}
Herkool replied on at Permalink Reply
What about 5.7?
I did:
$al = AssetList::getInstance(); 
$al->register('css', 'handle1', 'css/styles.css', array(), 'my_package'); 
$this->requireAsset('css', 'handle1');

And got this error:
Call to a member function requireAsset() on a non-object
WillemAnchor replied on at Permalink Reply
WillemAnchor
You can register them in your on_start in the package controller
Require them in your block controller or page_theme.php

http://documentation.concrete5.org/developers/assets/requiring-an-a...
events:
http://documentation.concrete5.org/developers/application-events/fu...
Herkool replied on at Permalink Reply
I want to include it at the active theme via package controller, not block. something similar to what MrKDilkington suggest for 5.6.