How to load the blueprint data

i know i can get the blueprint data if i create a pageobject.

but in my case its not so easy to get a proper parent every time (rules for allowed templates etc). so i would like to read the blueprint data without a page object. is that possible? this does not seem to work as expected.

$blueprint = new \Kirby\Cms\Blueprint([
        'model' => 'mytemplate'
    ]);
    var_dump($blueprint);

since the blueprints come from various plugins i can not simply read the yaml file.

the most generic i did come up was this

$tmp = new Page([
        'template' => $mytemplateName,
        'model' => $mytemplateName,
        'parent' => site()->homePage(),
        'slug' => time(),
    ]);
var_dump($tmp->blueprint()->fields());

the kirby()->blueprints() crawls all files even from plugins but only returns their names. i could copy that code but hoped there would be some prettier way…

But this - or rather - $kirby->extensions('blueprints') should then give you all paths to all blueprint files which you could then parse?

almost. see the original blueprints method i linked. one needs blueprints from extensions AND root(‘blueprints’), filtering by type,… :roll_eyes:

i am just wondering how to create an blueprint instance without a page/file object based on the blueprints the app know about? sure i could create an blueprint instance and forward a yaml file i searched for myself but… no very convenient.

The method returns all blueprints from extensions and the root blueprint folder

Array
(
    [files/default] => /Users/me/public_html/34/kirby/config/blueprints/file.yml
    [pages/default] => /Users/me/public_html/34/kirby/config/blueprints/page.yml
    [site] => /Users/me/public_html/34/kirby/config/blueprints/site.yml
    [pages/shop] => /Users/me/public_html/34/site/plugins/gallery/blueprints/shop.yml
    [pages/docindex] => /Users/me/public_html/34/site/plugins/kirby-helpsection-master/blueprints/docindex.yml
)

Unfortunately, the array keys need some tampering with to make them filterable by type.

:thinking:

Maybe this helps:

use Kirby\Cms\Blueprint;
var_dump( Blueprint::find('pages/mytemplate') );
2 Likes