-
Notifications
You must be signed in to change notification settings - Fork 73
Be able to add field assets conditionally #1058
Comments
Erm, what about this? class MyField extends BaseField {
static public $assets;
}
if(c::get('debug')) {
MyField::$assets = array(
'css' => array('style.css'),
'js' => array('script.js'),
);
} else {
MyField::$assets = array(
'css' => array('style.min.css'),
'js' => array('script.min.js'),
);
} |
Thanks, that works brilliantly to my current project. I will probably add it as a Kirby Secret. :) About the issue, do you think this is the solution we should use in the future?
So I still hope for some improvement in the panel core regarding this in the long run. |
I agree that this shouldn't be used in production plugins and fields. My recommendation: Always use minified assets. It doesn't make sense to have this conditional check only for local field development. You can always use source maps for debugging. |
Thanks for the suggestion about source maps. About the issue. If we need a more dynamic css, like using a color set in the config.php, you think it should be done like the code below, outside the class? Or do you think there is a way in the future to make it a part of the class? class MyField extends BaseField {
static public $assets;
}
MyField::$assets = array(
'css' => array('style.' . c::get('my.plugin.color') . '.css'),
'js' => array('script.js'),
); If you think it would be nicer to have it inside the class, reopen this issue? |
Now it looks like this in a field:
Related: https://forum.getkirby.com/t/set-field-asset-with---construct/7005
As far as I can tell there is no way to add assets conditionally. Let's say it make sense to do this:
or...
Because it's set as static variable, we can't control it. Maybe it could be used as a static asset (like it is now) OR be overwritten by the
__contruct
somehow?The text was updated successfully, but these errors were encountered: