Kirby

Kirby::plugin setting for passing data to the panel Vue front end

See this post for more information and a use case for what I’m about to describe.


It would be very useful to be able to pass some static server data to your plugin’s panel view. In the source of the panel page, you can see:

<script>window.panel = {"url":"http://localhost/ikarov/panel","site":"http://localhost/ikarov","api":"http://localhost/ikarov/api","csrf":"9e1534bfa938023d64360efbfedb4ed29fa2bf7e1d41b71efc5d96d66c34d964","translation":"en","debug":true,"search":{"limit":10}}</script>

This way, the panel Vue app gets some necessary server data. Well, my suggestion is to provide a way to add more data to this object. For example:

plugin’s index.php:

Kirby::plugin('hdodov/myplugin', [
  'panelData' => [
    'myvalue' => 42
  ];
]);

Then, in your index.js:

console.log(window.panel.plugins.data.myplugin.myvalue) // 42

Could you add your suggestion to our idea repository? https://github.com/getkirby/ideas/issues

This way the community can vote on all ideas which helps to inform our decision for the roadmap.

As written in my reply to your other post, you can still query API data from your component upon initialization of the component. This works great for my plugins – and also is how most of the Panel itself gets its information (besides these few variables that are crucial for starting the Panel.

Yep, I can query the data. But in order to do that, I would need to:

  1. Create a new API endpoint
  2. Use AJAX to load the data, which may be unnecessary bloat
  3. Because the data is loaded via AJAX, the plugin needs to wait for the data
  4. Due to the plugin having to wait for the necessary data, I need to delay its initialization which doesn’t seem to happen easily

It would be much simpler to just:

  1. Read the data

Depending on what you do it might also slow down every panel page load - no matter if the plugin itself is involved or not. Not saying that this shouldn’t be an option therefore. But also here a concrete use case would help a lot to an informed decision.

1 Like

I agree. My use case is kind of an edge case because I need that initial data in order to create a Vuex store and then start the plugin app. Pretty sure that a great portion of plugins don’t have that. Therefore it might not be a very important feature to have, but I should at least be able to initialize the plugin after the data is loaded over API. That would be enough for me, and it’s not yet possible.