# Problem with programmable-blueprints cookbook

**URL:** <https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 13, 2022, 12:19am UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463 "2022-01-13T00:19:02Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaro.io](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jaro.io/32/11374_2.png) [@jaro.io](https://forum.getkirby.com/u/jaro.io)\
**Post date:** [January 13, 2022, 12:19am UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/1 "2022-01-13T00:19:02Z")

</div>

🌻 🍃  
**hello everyone,**  
i just started with kirby and am glad to be joining this beautiful & vital community!

today i was playing around with the new panel cookbook for creating **programmable blueprints**. i love everything you have put together here @texnixe, it helps so much and my [filtered page sections](https://getkirby.com/docs/cookbook/panel/programmable-blueprints#page-blueprint-with-filtered-pages-sections) are populating nicely!

the only thing i noticed is, since i integrated the plugin, the first section in my site.yml is not showing up anymore _(pls see screenshots)_. looks like the plugin’s function is still being called on the panel homepage, despite having the if clause right at the start inside your `notes.php` _(in my setup it’s called `meals.php` though)_.

as soon as i disable the plugin, the section is rendering again.  
any idea why this is happening?

thanks a lot!  
✨

 ![Screenshot 2022-01-13 at 01.13.29](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/6/6e8f09a54ec4c477abd3509dd44c12c32a1a9979.png)  
 ![Screenshot 2022-01-13 at 01.10.10](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/e/e7086a6b975e4e776b42a755e84a6d3eed481d04.png)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 13, 2022, 12:33am UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/2 "2022-01-13T00:33:08Z")

</div>

Could you please post the blueprint that’s causing the error?

---

<div class="post-metadata">

**Author:** ![jaro.io](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jaro.io/32/11374_2.png) [@jaro.io](https://forum.getkirby.com/u/jaro.io)\
**Post date:** [January 13, 2022, 8:42am UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/3 "2022-01-13T08:42:18Z")

</div>

**yes, of course!**  
thank you for taking your time!

`site.yml`

* * *

```auto
title: Site

columns:
  left:
    width: 1/2
    sections:

        # primary pages
        primary:
            headline: Primary Pages
            type: pages
            empty: No pages found
            status: published
            templates:
                - home
                - shop
                - about
            image: icon

        # secondary pages
        secondary:
            headline: Secondary Pages
            type: pages
            empty: No pages found
            status: unlisted
            templates:
                - checkout
                - success
                - error
            image: icon

  right:
    width: 1/2
    sections:

        # databases
        databases:
            headline: Databases
            type: pages
            empty: No database found
            status: unlisted
            templates:
                - meals
                - categories
            image: icon

        # ecommerce
        ecommerce:
            headline: Ecommerce
            type: pages
            empty: No database found
            status: unlisted
            templates:
                - orders
                - shipping-methods
                - emails
            image: icon

```

as you can see, i am displaying my “meals page” _(the one with the dynamic blueprint)_ inside the “databases section”. but removing the template here, doesn’t seem to solve the issue.

🌳 🌿

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 13, 2022, 8:58am UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/4 "2022-01-13T08:58:53Z")

</div>

Thanks. But the error occurs for the first `primary` section, not the database section. Do the rest of the sections show up as intended?

And I assume `site.yml` is a the standard blueprint in the `/site/blueprints` folder, not in the plugin? And the only dynamic blueprint you are using is the meals blueprint?

---

<div class="post-metadata">

**Author:** ![jaro.io](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jaro.io/32/11374_2.png) [@jaro.io](https://forum.getkirby.com/u/jaro.io)\
**Post date:** [January 13, 2022, 9:01am UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/5 "2022-01-13T09:01:28Z")

</div>

@texnixe yes, that’s correct.

 ![Screenshot 2022-01-13 at 10.00.44](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/f/fced6c7931e03f3f00e039cd4754f44f262b74b7.png)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 13, 2022, 9:04am UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/6 "2022-01-13T09:04:01Z")

</div>

Could you post` index.php` and `meals.php` from your plugin, please?

---

<div class="post-metadata">

**Author:** ![jaro.io](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jaro.io/32/11374_2.png) [@jaro.io](https://forum.getkirby.com/u/jaro.io)\
**Post date:** [January 13, 2022, 9:11am UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/7 "2022-01-13T09:11:51Z")

</div>

**yup, here you go!**

`index.php`

* * *

```auto
<?php

use Kirby\Cms\App as Kirby;

Kirby::plugin('cookbook/dynamic-blueprints', [
    'blueprints' => [
        'pages/meals' => function ($kirby) {
            return include __DIR__. '/blueprints/pages/meals.php';
        },
    ]
]);

```

`meals.php`

* * *

```auto
<?php

$sections = [];

if ($page = page('meals')) {

    // create dynaimic sections
    foreach ($page->site()->find('categories')->children() as $category) {

        $sections[explode('/', $category)[1]] = [
            'headline' => $category->title()->value(),
            'type' => 'pagesdisplay',
            'status' => 'published',
            'layout' => 'cardlets',
            'empty' => 'No products yet',
            'query' => "page.children.filterBy('type', '==', '" . $category . "')",
            'templates' => 'meal',
            'image' => false,
            'info' => '{{ page.descr }}'
        ];
    }

    // add drafts
    $sections['drafts'] = [
        'headline' => 'Drafts',
        'type' => 'pages',
        'status' => 'draft',
        'empty' => 'No products yet',
        'templates' => 'meal',
        'image' => false,
        'info' => '{{ page.descr }}'
    ];
}

// create the array for the page blueprint with two columns
$yaml = [
    'title' => 'Meals',

    'image' => [
        'back' => 'white',
        'icon' => 'food',
        'color' => 'black'
    ],

    'options' => [
        'changeSlug' => false,
        'changeStatus' => false,
        'changeTemplate' => false,
        'changeTitle' => false,
        'delete' => false,
        'preview' => false,
        'update' => false,
        'duplicate' => false
    ],

    'sections' => $sections
];

return $yaml;

```

✨

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 13, 2022, 9:37am UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/8 "2022-01-13T09:37:20Z")

</div>

Ok, the error points to line 8 of meals.php, which is this line with the call to children:

```auto
foreach ($page->site()->find('categories')->children() as $category) {

```

I can reproduce the error and it helps if you wrap the first section in an if statement:

```auto
    if ($p = $page->site()->find('categories')) {

        foreach ($p->children() as $category) {

            $sections[explode('/', $category)[1]] = [
                'headline' => $category->title()->value(),
                'type' => 'pagesdisplay',
                'status' => 'published',
                'layout' => 'cardlets',
                'empty' => 'No products yet',
                'query' => "page.children.filterBy('type', '==', '" . $category . "')",
                'templates' => 'meal',
                'image' => false,
                'info' => '{{ page.descr }}'
            ];
        }
    }

```

---

<div class="post-metadata">

**Author:** ![jaro.io](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jaro.io/32/11374_2.png) [@jaro.io](https://forum.getkirby.com/u/jaro.io)\
**Post date:** [January 13, 2022, 3:07pm UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/9 "2022-01-13T15:07:17Z")

</div>

**thank you so much** for your wonderful support @texnixe, that did the trick! 🙏🏻 ✨

do you mind explaining why i needed to add this? because i thought the plugin only loads on my meals template, not on every page in the panel. is that not correct?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 13, 2022, 6:41pm UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/10 "2022-01-13T18:41:19Z")

</div>

> [@jaro.io](#):
>
> because i thought the plugin only loads on my meals template, not on every page in the panel.

Those page blueprints need to be loaded as well, e.g. for the sections to decide if a page should be listed at all, for preview images etc.

---

<div class="post-metadata">

**Author:** ![jaro.io](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jaro.io/32/11374_2.png) [@jaro.io](https://forum.getkirby.com/u/jaro.io)\
**Post date:** [January 26, 2022, 4:59pm UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/11 "2022-01-26T16:59:46Z")

</div>

@texnixe one more question… how do i now get the content of my dynamically created fields when building a template?

i cant do **`$page->xyz()`** because **xyz** is dynamic… so is there something like **`$page->content('xyz')`**?

thank youuu!  
⛅ ✨

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 26, 2022, 5:06pm UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/12 "2022-01-26T17:06:35Z")

</div>

I guess you are referring to the dynamic fields example? In the example, the field names are set to the page slug in the loop. So to fetch these fields, you would apply the same loop as in the dynamic blueprint.

---

<div class="post-metadata">

**Author:** ![jaro.io](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jaro.io/32/11374_2.png) [@jaro.io](https://forum.getkirby.com/u/jaro.io)\
**Post date:** [January 26, 2022, 5:19pm UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/13 "2022-01-26T17:19:48Z")

</div>

@texnixe in my dynamic blueprint loop _(the same from [above](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/7))_, i added other fields, like a `headline` and a `writer`. and because each field needs an individual name to store the content, i use the category name as a prefix.

of course i will need to use the same loop inside my template. i can also get the same category name _(my prefix)_ there. but then, how do i get to the content itself? because i guess i can’t do **`$page->$name . 'label'()`** here, right?

do you know what i mean?  
its a bit hard to explain…  
🌳

```auto
$sections[$name . 'intro'] = [
    'type' => 'fields',
    'fields' => [
        $name . 'label' => [
            'label' => $category->title()->value(),
            'type' => 'headline',
        ],
        $name . 'headline' => [
            'label' => 'Headline',
            'type' => 'writer',
            'nodes' => false,
            'marks' => '-italic -link'
        ],
    ],
];

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 26, 2022, 5:28pm UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/14 "2022-01-26T17:28:31Z")

</div>

> [@jaro.io](#):
>
> because i guess i can’t do **`$page->$name . 'label'()`** here, right?

You can, but you have to wrap the the concatenated string in curly braces:

```auto
$page->{$name . 'label'}()

```

---

<div class="post-metadata">

**Author:** ![jaro.io](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jaro.io/32/11374_2.png) [@jaro.io](https://forum.getkirby.com/u/jaro.io)\
**Post date:** [January 26, 2022, 5:30pm UTC](https://forum.getkirby.com/t/problem-with-programmable-blueprints-cookbook/24463/15 "2022-01-26T17:30:21Z")

</div>

perfect, thats exactly what i was looking for. again, thank you so much! what a beautiful & fast support here, wow! 🌻
