Using collection as options for select

How would I go about populating a page template select field with a collection?

Ho @punchfighter

I will create a static function in my theme ( Mytheme.php)

Example, of course you can make your own

public static function getPageTitle($collection_options, $path)

    $grav = Grav::instance();
    $page = $grav['page'];
    $collection = $page->evaluate([$collection_options => $path]);
    $titles = [];

    foreach ($collection as $item) {
        $titles[$item->title()] = $item->title();

    return $titles;

Then call it in your Blueprints:

   type: select
   label: My Label
   multiple: true
   data-options@: ['\Grav\Theme\Themename::getPageTitle', '@page.modular', '/path']
      type: commalist

See Here for Data options

Hope it helps

1 Like

Thanks. Your namespace seems to bork the thing, though.

Declaring $grav absolutely, as $grav = \Grav\Common\Grav::instance(); does the trick.

I think I need to brush up on namespace syntax because my brain is marinara right now.