Thank’s to the wonderful explanation at Plugin Command | Grav Documentation, I’m currently writing a cli command to use as bin/plugin <my plugin> <my command>.
Unfortunately, the docs, naturally, don’t cover everything and my PHP skills are so, so.
In my Plugin cli I need to access the currently active theme, its config and its directory (though the latter might not be absolutely necessary).
In a “live” instance, for example from <theme-name>.php
, I could get all that with something like
$grav = Grav::instance(); // or maybe $this->grav
$themecfg = $grav['config']['theme'];
$themedir = $grav['locator']->findResource('theme://', false);
But if I use this in the plugin cli code, the former is NULL and ‘theme://’ is invalid.
I can get the configs of all installed themes and the theme directory, though, with
$grav = Grav::instance();
$all_theme_cfgs = $grav['config']['themes']; // theme_s_, plural
$themes_dir = $grav['locator']->findResource('themes://', false);
So, I’m assuming, this is because the plugin cli instance didn’t initialize theme related stuff. So, how do I do this?