Access page routes from cli

Hi!

I’m using a plugin trough the client command.

I’m trying to get all the routes using this bunch of code:

$grav = Grav::instance();
$pages = $grav['pages'];
$routes = $pages->routes();

But the routes are always empty, any idea why? If I execute this code on a plugin within the application it works.

Thanks!

Grav follows an initialization process. Just calling instance() is not going to call the process() method, which is the one that triggers all the processors in https://github.com/getgrav/grav/tree/develop/system/src/Grav/Common/Processors.

See https://github.com/getgrav/grav/blob/develop/index.php#L42-L55

Ok thanks @flavio, I’ll try today!

To give a bit of context, my idea is to create a pre-cache plugin. I would like to cache the entire application before each deployment, so I would do something like: bin/grav clear-cache and then bin/plugin myPlugin precache.

  • I’m trying to use what has been done on the precache plugin, basically fetching all the routes using $page->content().
  • Using $grav = Grav::instance();, I then start the initialisation using $grav->process();
  • I need to do that before trying to access all the pages routes.
  • But I have an error: E_COMPILE_ERROR - Cannot declare class Grav\Theme\Busuu, because the name is already in use.
  • Busuu is just my current theme.

Anyone has an idea? Thanks!