Tags field, using both hardcoded options and a query

This reminds me of a similar challenge I faced a while ago - here’s an adaptation of the solution I built based on the suggestions from this forum thread, based on creating a page method (or page model) plugin:

<?php
Kirby::plugin('my/pagemethods', [
  'pageMethods' => [
    'customTagQuery' => function() {
      $customtags = ['hardcoded1','hardcoded2','hardcoded3'];
      foreach ( site()->index()->pluck("tags", ",", true) as $tag )
        $customtags[] = $tag;
      return array_unique( $customtags );
    },
  ]
]);

In your blueprint:

fields:
  category:
    label: Hardcoded and queried tags
    type: tags
    options: query
    query:
      fetch: page.customTagQuery
      text: "{{ arrayItem.value }}"
      value: "{{ arrayItem.value.slug }}"

This could likely still be improved upon, but maybe as a starting point? (I did a quick test run and it works in my test environment).

1 Like