Attempting to pull category (field) info from a specific blueprint

Following on from my previous question ( I was wondering if someone can help with the following.

On my blog posts page, I want to generate a list of categories that the user can then filter the posts by.

The place that these categories are defined is within my single post blueprint.

Is there a way that I can query this specific blueprint? I can now work out how to use the blueprint() method in relation to the page I’m on, or in relation to a specific page/post, but I want to simply access the info contained within a specified blueprint file, independent of any given page/post.

I know that the name of the blueprint is pages/article but can’t workout if there is a way of doing this.

Is this possible?

blueprints are always attached to page objects. if you need to read data from a specific blueprint file you could

  • fetch any existing page with that template to read the blueprint
  • read it manually with kirbys yaml class or
  • create a virtual page with same template as the blueprint and then read the blueprint data

I did consider that, but it would break if the page got deleted.

This looks beyond my expertise.

Hmm, this might be the solution. I’m having a read through.

This all seems like a lot of effort to avoid hard-coding a list though!

You can also load the blueprint

$bp = Kirby\Cms\Blueprint::load('pages/article');

This would give you an array though.

1 Like

why not store the categries in a page method (make it return an array of kirby objects) and use the query param of your select fields to populate the data. you could reuse the date from the page method elsewhere.

Or building on the above:

$props = Kirby\Cms\Blueprint::load('pages/note');
$props['model'] = page();
$bp = new Kirby\Cms\PageBlueprint($props);

Hi @texnixe

I ended up with the following:

$loadbp = Kirby\Cms\Blueprint::load('pages/article');
$loadbp['model'] = page();
$bp = new Kirby\Cms\PageBlueprint($loadbp);
$bpfields = $bp->fields();
$bpcats = $bpfields['articlecategories']['options'];

foreach ($bpcats as $bpcatk => $bpcatv) { ?>
	<a href="<?= $page->url(); ?>/cat:<?= $bpcatk; ?>"><?= $bpcatv ?></a>
<?php } ?>

I’ll pretty up the HTML side of things, but the functionality is there now.

TBH, I’m not really sure what these bits do:

$loadbp['model'] = page();
$bp = new Kirby\Cms\PageBlueprint($loadbp);

Do they simply allow Kirby to create a page type object, apply the blueprint and then use the fields() method on it?

As you can probably tell, I’m not really a developer, just an enthusiastic site builder that is always wanting to learn!

This adds the model property to the array that we previously stored in the $loadbp variable.

The page() helper just create a page instance, it’s probably a bit of a hack, but we need a way to pass the correct model to the props.

The next step then creates a new PageBlueprint instance, which is the same as you you called $page->blueprint().

Great, thanks for clarifying that for me. Also, thanks to @bnomei for your help too - I appreciate it.