Skip to content

Instantly share code, notes, and snippets.

@adamkiss
Last active March 5, 2020 20:12
Show Gist options
  • Save adamkiss/f35a2a3bd34ebc0228df9b7f894278f8 to your computer and use it in GitHub Desktop.
Save adamkiss/f35a2a3bd34ebc0228df9b7f894278f8 to your computer and use it in GitHub Desktop.
Dynamic Blueprints in Kirby
<?php
use Kirby\Cms\App as Kirby;
use Kirby\Data\Data;
Kirby::plugin('adamkiss/dynamic-blueprint', [
'hooks' => [
'system.loadPlugins:after' => function() {
// load base (this could be dynamic as well. Should even)
$fakeBlueprint = Data::read(__DIR__ . '/fake-kirby-request.yml');
// this is just a quick dirty code
$addFields = [];
foreach(
site()->index()->findBy('template', 'embed1')
->selfbuilder()->toBuilderBlocks() as $block
) {
$type = $block->_key()->toString();
switch ($type) {
case 'line':
$addFields[$block->fieldName()->toString()] = [
'type' => $type
];
break;
case 'info':
$addFields[$block->fieldName()->toString()] = [
'type' => $type,
'label' => $block->fieldLabel()->toString(),
'text' => $block->fieldText()->toString()
];
break;
case 'text': default:
$addFields[$block->fieldName()->toString()] = [
'type' => $type,
'label' => $block->fieldLabel()->toString(),
'size' => $block->fieldSize()->toString()
];
break;
}
}
// soecific place for preview
$fakeBlueprint['columns']['editable']['sections']['anothermain']['fields'] = $addFields;
// live Merge blueprints because why not.
kirby()->extensions['blueprints'] = array_merge(
kirby()->extensions['blueprints'],
['pages/embed1' => $fakeBlueprint]
);
}
]
]);
title: Default Page
pages: false
files: false
columns:
editor:
width: 1/2
sections:
main:
type: fields
fields:
selfbuilder:
label: Build yourself
type: builder
columns: 1
fieldsets:
textarea:
label: Textarea
fields:
fieldName:
width: 1/2
type: text
label: Field Name
size: small
fieldLabel:
width: 1/2
type: text
label: Field Label
size: small
fieldSize:
label: Field Size
type: radio
columns: 3
options:
small: Small
medium: Medium
large: Large
line:
label: Line
fields:
fieldName:
type: text
label: Field Name
size: small
info:
label: Info
fields:
fieldName:
width: 1/2
type: text
label: Field Name
size: small
fieldLabel:
width: 1/2
type: text
label: Field Label
size: small
fieldText:
type: textarea
label: Info Text
editable:
width: 1/2
sections:
anothermain:
type: fields
fields: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment