# Set default in pages field to all pages with template

**URL:** <https://forum.getkirby.com/t/set-default-in-pages-field-to-all-pages-with-template/29066>\
**Category:** Questions\
**Tags:** v3\
**Created:** [July 12, 2023, 11:33am UTC](https://forum.getkirby.com/t/set-default-in-pages-field-to-all-pages-with-template/29066 "2023-07-12T11:33:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alice](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/alice/32/13494_2.png) [@Alice](https://forum.getkirby.com/u/Alice)\
**Post date:** [July 12, 2023, 11:33am UTC](https://forum.getkirby.com/t/set-default-in-pages-field-to-all-pages-with-template/29066/1 "2023-07-12T11:33:18Z")

</div>

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

```auto
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")

```

---

<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:** [July 12, 2023, 11:55am UTC](https://forum.getkirby.com/t/set-default-in-pages-field-to-all-pages-with-template/29066/2 "2023-07-12T11:55:56Z")

</div>

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

> **[Programmable blueprints](https://getkirby.com/docs/cookbook/panel/programmable-blueprints)**
>
> Create blueprints programmatically with PHP

---

<div class="post-metadata">

**Author:** ![Alice](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/alice/32/13494_2.png) [@Alice](https://forum.getkirby.com/u/Alice)\
**Post date:** [July 12, 2023, 8:03pm UTC](https://forum.getkirby.com/t/set-default-in-pages-field-to-all-pages-with-template/29066/3 "2023-07-12T20:03:57Z")

</div>

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

```auto
<?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

---

<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:** [July 12, 2023, 9:24pm UTC](https://forum.getkirby.com/t/set-default-in-pages-field-to-all-pages-with-template/29066/4 "2023-07-12T21:24:02Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Alice](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/alice/32/13494_2.png) [@Alice](https://forum.getkirby.com/u/Alice)\
**Post date:** [July 13, 2023, 5:47am UTC](https://forum.getkirby.com/t/set-default-in-pages-field-to-all-pages-with-template/29066/5 "2023-07-13T05:47:33Z")

</div>

It works ! Thanks a lot
