Blueprint "create" not setting value

Hey, I’m trying to auto-generate url for new posts just based on the timestamp. I’m using the following blueprint and this helper function (In a plugin).

Helper function, I can see this being printed in the logs when I’m creating a new “Photo” post.

Kirby::plugin('notmyhostname/helpers', [
  'siteMethods' => [
    'unixtime' => function() {
      error_log('[notmyhostname/helpers] unixtime() called');
      error_log('[notmyhostname/helpers] Current time: ' . time());
      return (string) time();
    }
  ]
]);

The blueprint, the title is being set correctly. The slug is staying empty and so I can’t save the post in the Panel unless I fill it.

title: Photo
create:
  title: "{{ page.date.ToDate('j F Y') }}"
  slug: "{{ site.unixtime }}"
  fields:
    - date
columns:
  - width: 2/3
    fields:
      images:
        label: Images
        type: files
        multiple: true
        uploads:
          template: image
  - width: 1/3
    fields:
      title:
        label: Title
        type: text
        required: false
      date:
        label: Date
        type: date
        required: true
        default: today
      slug:
        label: Slug
        type: text
        required: true
        help: "The URL slug for the photo post."

Anything obvious I’m missing?

Thanks!

What’s the purpose of the slug field?

I wanted to show the generated url of the post in the panel…but the way you asked that made me question that. So I just removed it and everything works. I’m guessing it was overwriting the “internal” slug field of the post?

If there a way to still achieve that to display that slug in the panel, I’ve tried something like this but that doesn’t work as that would only be evaluated on creation as far as I understand.

      url:
        label: URL
        type: text
        help: "The url of the post."
        value: "{{ page.url }}"

Why not use an info field instead of a field that can be modified if it is purely informational? Although, I wonder what additional value there is in viewing a unix timestamp :thinking:

Why not use an info field instead of a field that can be modified if it is purely informational?

That would be an option, I don’t need to edit it. But what exactly do you mean by a “info” field. Type “info”? But then how would I set the value to be the full url (or just the timestamp, doesn’t really matter).

In the meantime I also found the original documentation that kinda explains why my “slug” field was overwriting the Kirby one, I shouldn’t have used a reserved word (“Do not use names that are reserved by native page methods”, Using fields | Kirby CMS).

      info:
        type: info
        text: "The slug of this page is {{page.slug}}"

Well, yes, using reserved field names is a bit problematic.

But the reason the field stayed empty was because you did not fill it with either a default value at page creation or in an page.create:after hook. Similar with your second attempt with the url field, you used a property named value that does not exist. But having said that, the default property for most fields doesn’t support query language, so using the correct property wouldn’t have helped in this case.

1 Like