Plugin using option() in route pattern?


I am trying to find a good way to enable rss-tracking for my podcaster plugin. I’m using a route which is defined in my plugins config

'pattern' => '(:all)/podtrack',

It would work that way, the user can just append podtrack to the rss-url and I can do the matomo calls in the route. But it would be better if the user could define a default rss-feed-slug, for example podcast-feed the route could then be something like:

'pattern' => '(:all)/' . option('mauricerenck.podcaster.defaultFeed'),

I didn’t find a way to get this up and running. Is it even possible to use option() at this point?


That should work, but have you set a path in the config? Better provide a fallback value:

'pattern' => '(:all)/' . option('mauricerenck.podcaster.defaultFeed', 'podtrack'),

Ouuuuhhhh… I think I got it… I set a default value, but I did it in my config.php using 'options' => […] doing this doesn’t seem to work, but setting a fallback works perfect!

Thank you!

It should also be possible to set a default value in your plugin options:

Is it possible to define the option and the route in the plugin and use this method? Perhaps there’s a different way to reference it when it’s defined in the same plugin?

It’s defined like this:

'options' => [
        'option-label' => 'sample',

But doesn’t work within the pattern in the same file:

'pattern' => "(:any)/". option('name.plugin-name.option-label', 'test') ."/(:any)",

You can use it, but you would have to use your default value as fallback, because your options array is not defined in the pattern line

'pattern' => "(:any)/". option('name.plugin-name.option-label', 'sample') ."/(:any)",

However, the option will be available later inside the callback:

        'pattern' => "(:any)/" . option('name.plugin-name.option-label', 'sample')  . "/(:any)",
        'action' => function() {
          return option('name.plugin-name.option-label');