Add a new field method in the kirby code

###Add a new field method in the kirby code to get the content of the blueprint file informations

There are serveral posts here and on Github, which discuss the posibility to get informations from the blueprint files outside the panel.
@bastianallgeier had made the decision in the past, that “Kirby” has to be indepent from the panel.
I think that is ok.

But sometimes developer of Kirby websites want to have knowledge of the blueprint file informations in templates or snippets.

So what about to add a new field method in the kirby code to get the content of the blueprint file informations in templates, snippets and so on.
I don’t say “to interpret the content of the blueprint file” in the Kirby core, but only to give an interface to the blueprint file informations.

This may e.g. be helpful with the texts of the checkbox fields to echo them in the corresponding templates.

Well, I think the interpret part IS the crucial part. Cause just the the content - here is how you can get it already:

$file = kirby()->roots()->blueprints() . DS . $page->intendedTemplate() . '.yml';
if(f::exists($file)) $blueprint = data::read($file, 'yaml');

With the upcoming version you can easily add new page methods (already on the development branch on GitHub), so you could add it yourself. Again - the more complicated part is the interpreting. And it has its reasons why core and panel are separated. For a lot of the problems that ask for blueprints as the solution an actually solution in the model/controller/template would work much better :wink:

1 Like

Or if someone really feels adventurous and cannot live without blueprints in the core, be really hackish and use the interpreter classes from the panel in the core:

// load all classes
load(array(
  'kirby\\panel\\models\\page\\blueprint'          => 'panel' . DS . 'models' . DS . 'page' . DS . 'blueprint.php',
  'kirby\\panel\\models\\page\\blueprint\\pages'   => 'panel' . DS . 'models' . DS . 'page' . DS . 'blueprint' . DS . 'pages.php',
  'kirby\\panel\\models\\page\\blueprint\\files'   => 'panel' . DS . 'models' . DS . 'page' . DS . 'blueprint' . DS . 'files.php',
  'kirby\\panel\\models\\page\\blueprint\\fields'  => 'panel' . DS . 'models' . DS . 'page' . DS . 'blueprint' . DS . 'fields.php',
  'kirby\\panel\\models\\page\\blueprint\\field'   => 'panel' . DS . 'models' . DS . 'page' . DS . 'blueprint' . DS . 'field.php',
  'kirby\\panel\\models\\page\\blueprint\\options' => 'panel' . DS . 'models' . DS . 'page' . DS . 'blueprint' . DS . 'options.php',
), kirby()->roots()->index . DS . 'panel' . DS . 'app' . DS . 'src');

$blueprint = new Blueprint($page->intendedTemplate());

But I would argue that this is not very smart. And that there are better solutions for the problems.

1 Like

Yes, and I hope that this will never be changed. The advantages of not being tied to the panel are much more important (security, if you want it) than being able to read the blueprints, the more so as you can find other ways to get the same result.

3 Likes

@jenstornell has build a Kirby plugin to get that, what I have suggested to the Kirby code:

Kirby Blueprint

Thank you very much!

HeinerEF

1 Like