Can one use php include()
to share common blueprint fields across a set of similar blueprints?
Why you donāt just try it and see, if it works?
@distantnative: I did, but it did not work. Maybe Iām doing something wrong though. Hereās an example blueprint:
<?php if(!defined('KIRBY')) exit ?>
title: Page
pages: true
fields:
title:
type: text
label: Name
placeholder: Used in navigation and lists.
opening:
<? include(kirby()->roots()->site() . DS . 'panel' . DS . 'blueprints' . DS . 'scaffolds' . DS . 'related_pages.php'); ?>
files: false
And the file getting included:
type: structure
label: Related Pages
fields:
page_uri:
label: Page
type: select
options: query
query:
page: containers
fetch: children
value: '{{uri}}'
text: '{{title}}'
entry: >
<a href="/panel/#/pages/show/{{page_uri}}/p:1">{{page_uri}}</a>
Any ideas?
Just tried it myself, but it doesnāt seem to work with an include
Itās probably due to the fact that include()
interprets the file getting included as PHP code; and it is YAML. Right, @bastianallgeier?
This would be a lovely feature!
I just tried this too, but the blueprint file does not seem to execute any custom php inside it, just ignores it.
You could use text pre-processing outside kirby for parsing blueprints from a shared source. Like using grunt and a watcher to append the shared fields at the end of blueprints. I think Iāll try that.
Some people would like to use .yaml files instead of .php for blueprints. That would make include()
definitely impossible, but not the feature itself. I can imagine an āimportā option like:
fields:
title:
label: title
type: text
import: my_nice_field
ā¦
Wondering when that would actually be useful. And itās yet another layer of abstraction.
So far Iām happy with cutting & pasting, but Iāve donāt have that many shared fields. Mainly the Visual Markdown Editor field in 6 blueprints, and with the exact same options in only 4 of them.
One could add a function to index.php which generates all the blueprints based on a template folder using mustache. Or less hacky one could request a new panel hook from @bastianallgeier which gets called āon opening new pageā popup.
@bastianallgeier and his team seams to have listened; blueprint snippets are there at your service: Tutorial: Global field definitions aka blueprint snippets Have fun, M.