Kirby Logic Field - v.1.2

With this plugin you don’t need to create a new field every time you need something simple in the panel. This field calls for a snippet that you have set in your blueprint.

Much more information and instructions is on Github.

3 Likes

:heart: for everything that makes kirby easier to extend!

2 Likes

I renamed the field, released a new version and made it so much simpler…

Blueprint

fields:
  my_logic_field:
    title: My logic field
    type: logic

config.php

kirby()->hook('pluginLogicField', function($field, $page) {
  echo $page->title();
  echo $field->name();

  //snippet('some-logic', ['field' => $field, 'page' => $page]);
});

1.0

  • Complete rewrite
  • Renamed from Kirby Fragment Field to Kirby Logic Field
  • Using a hook instead of a snippet. Only a config is needed.
  • Changed from a field to a plugin.

Version 1.1

Now it’s even simpler to add a new custom field. Instead of a hook, a simple c::set option is used.

Blueprint

fields:
  my_logic_field:
    title: My logic field
    type: logic

config.php

c::set('plugin.logic.field', function($field) {
  return '<p>' . $field->name() . ' ' . $field->page->title() . '</p>';
});

Changelog

Version 1.2

github.com/jenstornell/kirby-logic-field

1.2

  • Added snippet example to readme.
  • Updated the config example to include $page as well.
  • Sending $page separated from $field. Two objects instead of just $field.

To use a snippet a code like this would work:

c::set('plugin.logic.field', function($field, $page) {
  return snippet('logic-' . $page->intendedTemplate(), ['field' => $field, 'page' => $page], true);
});

The snippet would then be called like logic-default and have access to $field and $page objects.