Kirby 5 Testing panel view buttons: linking to a dynamic url on specific type of page?

I want to try to do 2 things with the new panel view buttons, testing Kirby5 beta.

  1. I’m trying to add a button for a specific type of page (say those using product.yml blueprints)
  2. then send the user to a url like https://example.com/my-product-page?parameter=test

Ideally I’d like to define this with some PHP logic, like check if this page actually needs to have this button or not.

Ignoring the need for some logic for now I tried to add the button through the blueprint, but using something like link: "{{page.url}}/?parameter=test is not possible. And in the config.php method does not seem to be working either.

What is the best method you would recommend using to add a dynamic URL in a panel view button like that?

Hm, doesn’t look as if query language works there

Ping @distantnative

Just to make sure, you are using beta.2 not beta.1?

For the logic part, I’d recommend defining the button via a custom Panel area (see section on Panel view buttons | Kirby CMS). There you can add your conditions. And then reference it by name in your blueprint.

Must admit that I don’t understand that example with the area, if I want the button in a page, why would I define it in a custom todos area? Wouldn’t it have to go into a page view?

Basti and I talked about it a little that it’s not always ideal where we placed our extension. But like dialogs, drawers and dropdowns, we implemented buttons also to be defined as part of an area. You could also extend the default site area with it. In the end it doesn’t matter much for buttons as we look them up in any area and the config when you reference them by name.

I think in a future version, we will also allow defining dialogs, drawers, buttons etc. without an area in the first place. But for now I thought it’s best to keep it consistent with the rest.

Actually, I think you could also put them in the config as closure and that would allow you as well to add logic:

'panel' => [
  'viewButtons' => [
    'myButton' => function ($page) {
      if ($page->isDraft() !== true) {
        return [...]
      }
    }
  ]
]

(The area option I added so that plugins can also ship certain buttons as they won’t have control over the config.)

Did not see there a beta2 released today. Updating now.

I agree with @texnixe, as you can see I did not mention the 3rd method listed in the documentation page because I honestly did not understand the example and wanted to make sure there was indeed no way to make it work with the 2 previous ones.

Just to be clear the last example you gave is supposed to be solely used in the config.php or can it be used in the index.php of a plugin also?

Ok, yes query support was just added in beta.2.

And for plugins you need to go the custom Panel area way. Even if it might be just a dummy area for now that hosts your buttons setups.

How I would do it (to get the same logic in place as in my example for the config above, but now in a plugin):

Kirby::plugin('my/plugin', [
  'areas' => [
    'my-plugin' => function () {
      return [
        'buttons' => [
          'myButton' => function ($page) {
            if ($page->isDraft() === false) {
              return [...];
            }
          }
        ]
      ];
    }
  ]
]);

:rofl: My question why simply 8 hours too early.
I managed to do 1. (adding to a blueprint) and 2. (using a query to generate the url.)

I will try to implement the more complex solution using a plugin.
Thanks for answering to my question!