Set default in pages field to all pages with template

How can I set the default to all pages that have a chosen template ?

title: Porfolio maker

columns:
  main:
    width: 2/3
    sections:
      fields:
        type: fields
        fields:
          toInclude:
            label: Pages to include
            type: pages
            default:
              - site.index(true).template("default")

I don’t think you can use a query for the default value, it must be a yaml-decodable value.

The only option for this that I can see is to use a “programmable blueprint” for the field, see

Following the programmable blueprint tutorial, this is what i’ve have right now:

<?php

$defaultArray = [];
$collection = site()->index()->filterBy('template', 'default');
$default = '';
foreach($collection as $page){
  $default = ' - ' . $page;
}
// it does not work with an array
// $default = [];
// foreach($collection as $page){
//   $default[] = ' - ' . $page;
// }


// create the array for the page blueprint with two columns
$yaml = [
    'title'   => 'Porfolio maker1',
    'columns' => [
        'main' => [
            'width'    => '2/3',
            'sections' => [
                'fields' => [
                    'type' => 'fields',
                    'fields' => [
                        'toInclude' => [
                            'label' => 'Pages to include',
                            'type' => 'pages',
                            'default' => $default

                        ]
                    ]
                ]

            ], // dynamically generated sections from above
        ]
    ]
];

return $yaml;

The code works with a single string, but not with an array of strings, which is the whole point. What syntax should I use to generate the correct yaml from the php array ? i’m not used to working with yaml

Also you need is an array that you pass as default, the yaml-encoding rest is done automatically, i.e. you don’t have to add the dashes…

It works ! Thanks a lot