PHPackages                             steirico/kirby-plugin-custom-add-fields - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. steirico/kirby-plugin-custom-add-fields

ActiveKirby-plugin

steirico/kirby-plugin-custom-add-fields
=======================================

Custom fields for Kirby's add dialog. This plugin allows to define the fields shown on the page add dialog in a page's blueprint.

2.0.0(4y ago)364.2k4[8 issues](https://github.com/steirico/kirby-plugin-custom-add-fields/issues)MITPHP

Since Apr 26Pushed 3y ago5 watchersCompare

[ Source](https://github.com/steirico/kirby-plugin-custom-add-fields)[ Packagist](https://packagist.org/packages/steirico/kirby-plugin-custom-add-fields)[ RSS](/packages/steirico-kirby-plugin-custom-add-fields/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (1)Versions (28)Used By (0)

Kirby custom Add Fields Plugin
==============================

[](#kirby-custom-add-fields-plugin)

Custom fields for Kirby's add dialog. This plugin allows to define the fields shown on Kirby's page add dialog in the corresponding page's blueprint.

[![Demo](assets/demo.gif)](assets/demo.gif)

Installation
------------

[](#installation)

Use one of the alternatives below.

### Download

[](#download)

Download and copy this repository to `/site/plugins/kirby-plugin-custom-add-fields`.

### Git submodule

[](#git-submodule)

```
git submodule add https://github.com/steirico/kirby-plugin-custom-add-fields.git site/plugins/kirby-plugin-custom-add-fields
```

### Composer

[](#composer)

```
composer require steirico/kirby-plugin-custom-add-fields
```

Compatibility
-------------

[](#compatibility)

KirbyPluginpre 3.61.5.03.6 and newer2.0.0 and newerUsage
-----

[](#usage)

### Defining custom Add Fields

[](#defining-custom-add-fields)

This plugin adds the extra property `addFields` to page blueprints. To define custom add fields do as you would do for [defining regular fields](https://getkirby.com/docs/reference/panel/sections/fields)but put the definition in the property `addFields`.

> `/blueprints/pages/remote.yml`:
>
> ```
> title: Blueprint with custom Add Fields
>
> fields:
>     # field definitions
>     title:
>         label: Title
>         type: text
>     content:
>         label: Content
>         type: textarea
>
> # custom add fields definition
> addFields:
>     title:
>         label: Title
>         type: text
>         required: true
>         icon: title
>
>     remoteUrl:
>         label: URL to external Content
>         type: select
>         options:
>             'https://jaspervdj.be/lorem-markdownum/markdown-html.html?no-wrapping=on': Lorem Markdownum
>             'https://raw.githubusercontent.com/steirico/kirby-plugin-custom-add-fields/master/README.md': README
>         icon: url
> ```

### Reusing and Extending

[](#reusing-and-extending)

The plugin supports the `extends` keyword for reusing and extending fields:

> `/blueprints/pages/event.yml`:
>
> ```
> ....
> addFields:
>     extends: fields/event-common
>     title:
>         label: Title
>         type: text
>     host:
>         extends: fields/contact
>         label: Event Host
> ```

See the [kirby docs](https://getkirby.com/docs/guide/blueprints/extending-blueprints) for more information on reusing and extending field.

In such a manner, kirby's default add fields (`title` and `slug`) can be reused and extended:

> `/blueprints/pages/book.yml`:
>
> ```
> ....
> addFields:
>     # Reuse title and slug
>     # - kirby 3.6 and newer
>     extends: fields/default-add-fields
>     # - pre kirby v3.6
>     # extends: fields/legacy-default-add-fields.yml
>
>     # Add custom fields
>     isbn:
>         label: ISBN
>         type: text
> ```

### Using custom Add Fields

[](#using-custom-add-fields)

Values of custom add fields that correspond to fields of the page blueprint are taken into account for the new page straightforwardly. In the example above the value of `title` in the add page dialog will be set as page's `title`.

### `slug` Handling

[](#slug-handling)

In order to have kirby adding pages correctly the property `slug` has to be set. There are three ways to define a page's `slug`:

1. Add a custom add field named `slug` in order to define the `slug` manually.
2. If a field named `slug` is missing the plugin will set the `slug` based on the current timestamp.
3. Set/overwrite the `slug` in a pages hook script (see below).

### Using custom Add Fields in Hook Scripts

[](#using-custom-add-fields-in-hook-scripts)

The values of the custom add fields can be used on the server side for modifying the page to be added.

To do so one can register a [`page.create:after` hook](https://getkirby.com/docs/reference/plugins/extensions/hooks) and modify the `page` object.

The plugin also registers a generic hook which automatically detects and calls the [page model's](https://getkirby.com/docs/guide/templates/page-models) static method named `hookPageCreate($page)`. Define a page model and the method as follow:

> `/site/models/remote.php`:
>
> ```
>
