# Plugin using option() in route pattern?

**URL:** <https://forum.getkirby.com/t/plugin-using-option-in-route-pattern/12842>\
**Category:** Questions\
**Tags:** v3\
**Created:** [February 12, 2019, 4:30pm UTC](https://forum.getkirby.com/t/plugin-using-option-in-route-pattern/12842 "2019-02-12T16:30:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mauricehh](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mauricehh/32/13439_2.png) [@mauricehh](https://forum.getkirby.com/u/mauricehh)\
**Post date:** [February 12, 2019, 4:30pm UTC](https://forum.getkirby.com/t/plugin-using-option-in-route-pattern/12842/1 "2019-02-12T16:30:31Z")

</div>

Hi,

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?

Thanks!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 12, 2019, 4:40pm UTC](https://forum.getkirby.com/t/plugin-using-option-in-route-pattern/12842/2 "2019-02-12T16:40:54Z")

</div>

> [@mauricehh](#):
>
> option(‘mauricerenck.podcaster.defaultFeed’)

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

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

```

---

<div class="post-metadata">

**Author:** ![mauricehh](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mauricehh/32/13439_2.png) [@mauricehh](https://forum.getkirby.com/u/mauricehh)\
**Post date:** [February 12, 2019, 4:45pm UTC](https://forum.getkirby.com/t/plugin-using-option-in-route-pattern/12842/3 "2019-02-12T16:45:33Z")

</div>

> [@texnixe](#):
>
> That should work, but have you set a path in the config? Better provide a fallback value:

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!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 12, 2019, 4:54pm UTC](https://forum.getkirby.com/t/plugin-using-option-in-route-pattern/12842/4 "2019-02-12T16:54:37Z")

</div>

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

[https://getkirby.com/docs/reference/plugins/extensions/options](https://getkirby.com/docs/reference/plugins/extensions/options)

---

<div class="post-metadata">

**Author:** ![HYR](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/hyr/32/12830_2.png) [@HYR](https://forum.getkirby.com/u/HYR)\
**Post date:** [July 16, 2021, 10:43pm UTC](https://forum.getkirby.com/t/plugin-using-option-in-route-pattern/12842/5 "2021-07-16T22:43:54Z")

</div>

> [@texnixe](#):
>
> `option('mauricerenck.podcaster.defaultFeed', 'podtrack')`

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:

```auto
'options' => [
        'option-label' => 'sample',
    ],

```

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

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

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 17, 2021, 6:30am UTC](https://forum.getkirby.com/t/plugin-using-option-in-route-pattern/12842/6 "2021-07-17T06:30:56Z")

</div>

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

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

```

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

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

```
