Load blueprint data of one template into another

Hi,

is it possible to load a blueprint of one template (i.e. templateA) and use it’s methods like

$blueprintA->section('bla'); // or
$blueprintA->fields();

in templateB?

I’ve tried

Blueprint::load('pages/templateA')

but this returns and array, not an Object.

Ok, I can get it like this, but it doesn’t feel like it’s the most elegant solution:

$blueprintA = $site->index(true)->filterBy('intendedTemplate', 'templateA')->first()->blueprint();

This seems to work:

$blueprint = new Kirby\Cms\Blueprint(array_merge(['model' => 'home'], Kirby\Cms\Blueprint::load('pages/home')));
dump($blueprint->fields());
1 Like

Ahhh, You’re a master! Tanks so much! :see_no_evil:
I already tried digging into new Blueprint but it didn’t work.
Thank YOUU!!! Have a nice weekend! =)

1 Like

Unfortunately I get an InvalidArgumentException - Invalid section model when trying to get a section by name. Tabs and fields work flawlessly.
Do You have any hint?

I can reproduce this, I guess the problem is the model thingy where I don’t really know what is expected there.
I’ll try to dig deeper.

Thank You!
I don’t know if this helps, the cookbook part says: " This returns a Kirby\Cms\Section object, which you can further query.", but I wouldn’t know how to modify the new Blueprint accordingly :confused:

$blueprint = new Kirby\Cms\PageBlueprint(array_merge(['model' => $page], Kirby\Cms\Blueprint::load('pages/album')));
dump($blueprint->section('images'));

While this seems to work, I guess the idea here is to actually pass the page object that belongs to the blueprint, but then you might as well call the blueprint() method on the actual page (but querying the complete site()->index() just to get a value from a blueprint seems to be overkill.

Yes indeed, that’s why I didn’t feel very comfortable with my first try.

Your solution works very well for my use case.
Again, thank You as always for Your quick reply! Can’t count, how many times Your support in this forum has helped me solving some problems! <3