Default values in page creation dialog

Is it possible to add default values to fields like title, url appendix /slug, date (like: next sunday) and such, so that the fields in the dialog are pre-filled? I tried a few things in the blueprint, but they didn’t work. See example with default for title below.

create:
  title:
    label: Titel
    default: Wochenrückblick KW/2023 
  fields:
    - published
    - subtitle
  redirect: true
  status: draft  

published is a datefield, not sure if i can use anything like “next sunday” in here.

          published:
            label: Published on
            width: 1/2
            type: date
            display: DD.MM.YYYY
            time: true
              display: HH:mm
              step: 1
              default: now + 1 day  
              width: 1/1 
            notation: 24  

Anyway, the field shows up in the dialog but it’s empty. Would be awesome if it was prefilled.

Trying to do the same thing here. I need to use a query that picks a date from the parent page. The default works on the actual page, but not in the create dialog.

Same here. I’ve created an issue Default values missing in page creation dialog · Issue #6229 · getkirby/kirby · GitHub

Fixed in Version 4.1.0

Yes you’re right 4.1.0 fixes it.

I also need to correct my previous comment:
I thought it was possible to use queries for default values, but it does not seem to work anywhere. For comparison queries do work in the help text but not for default. Would be super useful if we could use queries so it can be based on something the user previously has entered.

If this is something that is not on the roadmap, is their any way of manipulating the default values before the dialog is displayed, with a custom model, hook or something…? @texnixe

Might be possible if you create the blueprint via PHP, but only if the parent page is known, because in programmable blueprints you don’t have access to the current page.

So something like this will work:

'fields' => [
  'date' => [
  'type'   => 'date',
  'default' => page('notes')->date()->toDate('Y-m-d'),
],

The update is nice, but i think this still doesn’t work for me, cause i can’t see a way to get the date and calendarweek of “next sunday” which i need in the slug and title. I built a workaround that is okay for me: a new template that does all stuff (get the date of next sunday and such) and creates a new page in the place where it should be and with all the defaults i need. The template is assigned to a hidden page i open from the panel. Adding a button to do so could be done to save 1 or 2 clicks but it was too much overload for such a simple task imho.

Note that you can use values such as

default: now
default: + 3 days
default: this sunday

etc.

Yeah, it works in my date field (published) but not in the slug and title, right? I tried things like these

create:
  title: 'Wochenrückblick KW{{ page.published.toDate("W") }}/{{ page.published.toDate("Y") }}'
  status: draft
  slug: '/blog/wochenrueckblick-kw{{ page.published.toDate("W") }}-{{ page.published.toDate("Y") }}'

...
          published:
            label: Published on
            width: 1/2
            type: date
            display: DD.MM.YYYY
            default: next sunday
            time: true
              display: HH:mm
              step: 1
              width: 1/1 
            notation: 24  

That should actually work

But this is wrong, what is the blog part doing there? Should be

  slug:  'wochenrueckblick-kw{{ page.published.toDate("W") }}-{{ page.published.toDate("Y") }}'

Might be possible if you create the blueprint via PHP, but only if the parent page is known, because in programmable blueprints you don’t have access to the current page.

Ok this is interesting… I’ve never done blueprints this way, let’s see if I have time to test. But… I need to fetch the date of a sibling “event” page, do some work with that, and use as default for the page being created. The parent page is a “tour” page and there are multiple. So I guess it won’t work?

Right, that won’t work.

Another option: Overwrite the date field with your own, changing the default property to support query strings. Basically like here with the number field: Dynamic default number field - #2 by texnixe

'props' => [
	'default' => function ($default = null): string {
		return $this->toDatetime($this->model->toString($default)) ?? '';
	},
]

THAT is awesome. Thanks!

still doesn’t work, it results in ‘wochenrueckblick-kw-’

{{ page.published.toDate("W") }}

seems t be empty or undefined?!

Could you please provide the complete blueprint for testing?

yes, of course

title: Rückblick

#https://getkirby.com/docs/reference/panel/blueprints/page#sorting
num: '{{ page.published.toDate("Ymd") }}'

create:
  #https://github.com/getkirby/kirby/releases/tag/4.1.0
  title: "Wochenrückblick KW{{ page.published.toDate('W') }}/{{ page.published.toDate('Y') }}"
  #redirect: true
  status: draft  
  slug:  'wochenrueckblick-kw{{ page.published.toDate("W") }}-{{ page.published.toDate("Y") }}'
  subtitle: 'Wochenrückblick KW{{ page.published.toDate("W") }}/{{ page.published.toDate("Y") }}'

columns:
  main:
    width: 2/3
    sections:
      fields:
        type: fields
        fields:
          subtitle:
            label: Subtitle/Description
            type: text  
            width: 1/2          

          published:
            label: Published on
            width: 1/2
            type: date
            display: DD.MM.YYYY
            default: next sunday 15:00
            time: true
              display: HH:mm
              step: 1
              width: 1/1 
              notation: 24  

          hidefromrss:
            type: toggle
            label: Hide from RSS
            icon: hidden
            width: 1/6
            text: 
              - "no"
              - "yes"

          hidefromweb:
            type: toggle
            label: Hide from Web
            icon: hidden
            width: 1/6
            text: 
              - "no"
              - "yes"              

          noindex:
            type: toggle
            label: robot no-index
            icon: hidden
            width: 1/6
            text: 
              - "no"
              - "yes"    
         
          lastmod:
            label: last mod?
            icon: clock
            type: toggle
            width: 1/6
            text: 
              - "no"
              - "yes"

          hidegallery:
            label: hide gallery?
            icon: image
            type: toggle
            width: 1/6
            defaut: "no"
            text: 
              - "no"
              - "yes"        

          text:
            type: textarea            
            size: large
            label: Text/Markdown
          outro:
            type: writer 
            default: — Sascha
          secret_code:
            label: Code für extra Infos
            type: text
          secret_text:
            label: Secret Extra (nur mit Code sichtbar)
            type: textarea
            size: small               
  sidebar:
    width: 1/3
    sections:      
      settings:
        type: fields
        fields:
          tags:
            label: Tags
            type: tags  
            options: 
              - Wochenrückblick
              - WMDEDGT
              - assbachSingt
              - webdev
              - FOC
              - Gedanken
              - kirby
            default: Wochenrückblick
            
          mastodon_url:
            label: Mastodon-Link/Initial Post
            type: url 
          
          ogimage:
            label: OG:image
            type: url
            icon: image
         
          assbachsingt:
            label: assbach Singt (pagess)
            type: pages     
            query: site.find("assbach-singt").children.filterBy("template", "song")
            sortBy: published 
            flip: true 

      files:
        label: Bilder
        type: files    
        template: image


The problem is that the field you want to use is not present in the list of fields, so you have to add the published field to the list of fields within the create dialog.

create:
  #https://github.com/getkirby/kirby/releases/tag/4.1.0
  title: "Wochenrückblick KW{{ page.published.toDate('W') }}/{{ page.published.toDate('Y') }}"
  #redirect: true
  slug:  'wochenrueckblick-kw{{ page.published.toDate("W") }}-{{ page.published.toDate("Y") }}'
  subtitle: 'Wochenrückblick KW{{ page.published.toDate("W") }}/{{ page.published.toDate("Y") }}'
  fields:
    - published
1 Like

okay, i see. Thank you. This works for title and slug now, but not for the other custom field “subtitle”, i tried adding it to the fields, but in the dialog it’s empty

Because this feature only works for title and slug, not for other fields. If you want to prefill other fields, it probably makes more sense to create a page model.

1 Like

I see, thank you. I`ll stick to my workaround or use the blueprint as far as it works now but look into the page model idea later. Thank you