Accessing content from columns in blueprint

Hi there, I was wondering if it is somehow possible to access the filelds/sections from a column of a blueprint?

ex:

columns:
  first: 
    width: 1/3
      fields:
        ....
  second:
    width: 2/3
      fields:
        ...

and then I access it in the php something like:
$page->columns()->first()

to get only the values from the fields inside this column from the blueprint?
obviously this is not working as I showed above but I was wondering if this is somehow possible.

You can use $page->blueprint() to get all information present in your blueprint: https://getkirby.com/docs/cookbook/templating/blueprints-in-frontend

If you do a

dump($page->blueprint());

you can inspect the PageBlueprint object and take it from there.

Oh wow! this is great! :scream:
exactly what I was looking for, thanks @texnixe :pray:

Hi @texnixe, sorry for bothering again. But I ran into an issue with the blueprint object. It started out all fine, but then I noticed that when I am logged out of Kirby it doesn’t show my content and my arrays are empty.

It does show me the blueprint fields, but the data array is empty. As soon as I log in, my content is back. All of them are public/listed. Is there some access issue or something that I am overseeing?

Hm, I‘m not aware of the blueprint method needing authentication. Could you post your code, please?

So my Blueprint is this:

title: Modular Page Two Columns
icon: document
options:
  changeTemplate:
    - p-modular
    - p-modular-two-column

columns:
   - width: 2/4
      sections:
        mainContent:
          headline: Modular Page
          type: pages
          status: all
          info: "{{ page.intendedTemplate }}"
          templates:
            - c-subheading
            - c-text-single
            - c-gallery
            - c-text
            - c-collection
  - width: 1/4
      sections:
        sidebar:
          type: pages
          status: all
          headline: Sidebar
          info: "{{ page.intendedTemplate }}"
          templates:
            - c-aside-text-image-single
            - c-aside-collection
            - c-aside-subheading
  - width: 1/4
      sections:
        additional:
          type: fields
	...

And my php is like this:


<?php
  $mainContent = $page->blueprint()->section("mainContent")->data();
  $mainContentIDs = [];
    foreach($mainContent as $main):
      array_push($mainContentIDs, $main["id"]);
    endforeach;

  $sidebar = $page->blueprint()->section("sidebar")->data();
  $sidebarIDs = [];
    foreach($sidebar as $side):
      array_push($sidebarIDs, $side["id"]);
    endforeach;
?>

<div class="p-modular-two-column--grid">
  <section class="p-modular-two-column__main-components--grid">
    <?php foreach ($page->children()->listed() as $component) : ?>
      <?php if(in_array($component->id(), $mainContentIDs)): ?>
        <?php snippet($component->intendedTemplate(), compact('component'));?>
      <?php endif; ?>
    <?php endforeach; ?>
    </section>
    <aside class="p-modular-two-column__aside-components--grid">
      <?php foreach ($page->children()->listed() as $component) : ?>
        <?php if(in_array($component->id(), $sidebarIDs)): ?>
          <?php snippet($component->intendedTemplate(), compact('component'));?>
        <?php endif; ?>
      <?php endforeach; ?>
    </aside>
  </div>

<?php snippet('footer'); ?>

Well, I don’t know if this makes any sense what I am doing here :sweat_smile:
But what I want to achieve is that I have this two column layout and I show my pages form the sections like modular components. I guess I could also filter the data through the naming c-aside:thinking:

But anyways… when I dump for example dump($sidebar) when I am logged out, then its an empty array. when I am logged in it works.

Ok, seems like the data does indeed need authentication.

Question: Why do you need to access the blueprint data to achieve what you are trying to achieve? You might as well filter your pages by their templates (if I haven’t missed anything)?

I see, hmm. Yeah I guess I am overcomplicating things here… I will use some filter! thanks for the help!