# Kirby3 blueprint text field dynamic default value from page title

**URL:** <https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898>\
**Category:** Questions\
**Tags:** v3\
**Created:** [July 26, 2020, 6:14pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898 "2020-07-26T18:14:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![something-strange](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/something-strange/32/8796_2.png) [@something-strange](https://forum.getkirby.com/u/something-strange)\
**Post date:** [July 26, 2020, 6:14pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/1 "2020-07-26T18:14:58Z")

</div>

Hi all,

Back with another question, ha… I can get the dynamic (newly created page title) passed into the ‘placeholder’ and ‘help’ props of my blueprint, but the ‘default’ prop isn’t working:

```
titleLine1:
  type: text
  label: Title Format
  default: "{{ page.title }}"
  placeholder: "{{ page.title }}"
  help: The {{ page.title }} shows up here too!
  counter: false
  width: 1/2

```

* * *

Default value not showing “Abc 123” (page title):

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/6/6968f7b41f8b8a00e9a023be7194b55c90c98812.png)

But placeholder works when I clear out the field:

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/e/ed846fc3130ce1ce574eeb74973b0111fb13cdc8.png)

* * *

I’m looking into the page hook create:after plugin stuff, but that isn’t working either.

As always, thanks for your help ⚡

---

<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 26, 2020, 7:59pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/2 "2020-07-26T19:59:22Z")

</div>

I think in most cases, you can only use a string as default value. I’m not even sure if the title even exists at the time Kirby determines the default values for a new page.

---

<div class="post-metadata">

**Author:** ![something-strange](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/something-strange/32/8796_2.png) [@something-strange](https://forum.getkirby.com/u/something-strange)\
**Post date:** [July 26, 2020, 8:26pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/3 "2020-07-26T20:26:10Z")

</div>

This is what’s so confusing about Kirby… I mean, if you can interpolate the placeholder and help props, why can’t you just snag the value for the default prop value? In my screenshot I can literally see the title being rendered as placeholder and in the help field.

I’ve been burning so many hours debugging little/big things like this, hah, feel like Kirby 2 was 100x easier to use. But I’m torn, because I’m using Jakub’s super nice [Kirby Vue Starterkit](https://github.com/jmheretik/kirby-vue-starterkit), so I’m trying to like that K3 is built with Vue, but I’m so confused with issues like this… ha

So, can I use a page.create:after hook to drop that in to the default value? I mean I tried this but it didn’t work, but there should be some way to get this if the placeholder and help props can render it.

---

<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 26, 2020, 9:11pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/4 "2020-07-26T21:11:37Z")

</div>

Yes, you can use either a hook or a page model.

However, what’s the purpose of having a second field with the value of the title?

---

<div class="post-metadata">

**Author:** ![something-strange](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/something-strange/32/8796_2.png) [@something-strange](https://forum.getkirby.com/u/something-strange)\
**Post date:** [July 26, 2020, 9:24pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/5 "2020-07-26T21:24:25Z")

</div>

Haha, excellent question 😅 This was a “client request” to format the title on 2 lines in certain areas…

For instance, a page title may be  
**Project Name - A Fun Title**

But on a certain area of the site, the title will be formatted to their liking on two lines:

**Project Name**  
A Fun Title

They may want a hyphen in the original title for SEO / browser title, but in the format area on two lines they want to delete the hyphen and drop on two lines etc.

So, my goal was to auto-populate a small textarea field so the first line was the full title, then they could hit a hard return so then I could use the $data-\>title()-\>kt() and break this out on two lines.

* * *

So, I’m really sorry to trouble you, but can you provide an example of the page.create:after hook (or another hook?) in how I could grab the page title to use in my blueprint? I tried a few ways but no luck.

Thanks a million @texnixe!

---

<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 26, 2020, 9:28pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/6 "2020-07-26T21:28:38Z")

</div>

Like in the date hooks in the other thread, you would have to update the page. Or you adapt the [model I provided in the same thread](https://forum.getkirby.com/t/kirby3-blueprint-or-hook-to-show-info-of-which-user-created-modified-a-page/18883/27). What’s best depends…

Hook: Can more easily be applied to multiple page types if necessary.  
Page model (create method): Modifications happen when stuff is written to file, not afterwards.

---

<div class="post-metadata">

**Author:** ![something-strange](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/something-strange/32/8796_2.png) [@something-strange](https://forum.getkirby.com/u/something-strange)\
**Post date:** [July 26, 2020, 9:52pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/7 "2020-07-26T21:52:46Z")

</div>

> [@texnixe](#):
>
> Or you adapt the [model I provided in the same thread](https://forum.getkirby.com/t/kirby3-blueprint-or-hook-to-show-info-of-which-user-created-modified-a-page/18883/27)

Well, I tried the model example, but I didn’t see anything happen. I changed class NotePage to ProjectPage accordingly, and it lives here: `/site/models/project.php`

`$props['content']['newTitle'] = $props['content']['title']`

My blueprint looks like this:

```
titleFormat:
  type: textarea
  label: Title Format
  default: "{{ page.newTitle }}"

```

But, I didn’t see anything update.

* * *

So then I went back to hooks… set up a new plugin:

```
<?php

Kirby::plugin('ssk3-fields/titleformat', [
  'hooks' => [
    'page.create:after' => function ($page) {
      $page->update([
        'autoTitle' => $page->title()->value()
      ]);
    },
    'page.update:after' => function ($newPage, $oldPage) {
      $newPage->update([
        'autoTitle' => $newPage->title()->value()
      ]);
    },
    'page.changeTitle:after' => function ($newPage, $oldPage) {
      $newPage->save([
        'autoTitle' => $newPage->title()->value()
      ]);
    }
  ]
]);

```

And update my blueprint like so:

```
titleFormat:
  type: textarea
  label: Title Format
  default: "{{ page.autoTitle }}"

```

Wouldn’t `page.autoTitle` get updated on any of these 3 hooks?

---

<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 26, 2020, 9:55pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/8 "2020-07-26T21:55:03Z")

</div>

> [@something-strange](#):
>
> `titleFormat:`

Because your field name is titleformat, settting the title to the title value doesn’t make sense. And the default value in the blueprint doesn’t make sense either in this case.

As I already mentioned in the other tthead, a default value only works at page creation and since we know that the query string doesn’t worrk anyway, you can remove the default value altogether.

---

<div class="post-metadata">

**Author:** ![something-strange](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/something-strange/32/8796_2.png) [@something-strange](https://forum.getkirby.com/u/something-strange)\
**Post date:** [July 26, 2020, 9:57pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/9 "2020-07-26T21:57:26Z")

</div>

Sorry! I had a typo, I just edited my model example with ‘newTitle’

---

<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 26, 2020, 9:59pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/10 "2020-07-26T21:59:37Z")

</div>

So, with the model, the blueprint and the hook in place, you will now end up with three differently named fields: newtitle, autotitle and titleformat, hurray!

---

<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 26, 2020, 10:00pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/11 "2020-07-26T22:00:57Z")

</div>

What’s the name of the blueprint?

---

<div class="post-metadata">

**Author:** ![something-strange](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/something-strange/32/8796_2.png) [@something-strange](https://forum.getkirby.com/u/something-strange)\
**Post date:** [July 26, 2020, 10:01pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/12 "2020-07-26T22:01:18Z")

</div>

Blueprint is `project.yml`

---

<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 26, 2020, 10:01pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/13 "2020-07-26T22:01:50Z")

</div>

Ok, then project.php model is at least correct.

---

<div class="post-metadata">

**Author:** ![something-strange](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/something-strange/32/8796_2.png) [@something-strange](https://forum.getkirby.com/u/something-strange)\
**Post date:** [July 26, 2020, 10:02pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/14 "2020-07-26T22:02:48Z")

</div>

Haha yes! (_pumps fist_)

So if we go with model, and not the hooks, how would I extend the model to drop in the title?

---

<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 26, 2020, 10:02pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/15 "2020-07-26T22:02:54Z")

</div>

> [@something-strange](#):
>
> `$props['content']['newTitle'] = $props['content']['title']`

Should be

```auto
$props['content']['titleformat'] = $props['content']['title'];

```

---

<div class="post-metadata">

**Author:** ![something-strange](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/something-strange/32/8796_2.png) [@something-strange](https://forum.getkirby.com/u/something-strange)\
**Post date:** [July 26, 2020, 10:07pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/16 "2020-07-26T22:07:21Z")

</div>

Closer…warmer… hah. So I have this for my full extended model:

```
<?php

class ProjectPage extends Page {
  public static function create(array $props): Page {
    $props['content']['titleformat'] = $props['title'];
    return parent::create($props);
  }
}

```

and the blueprint is like so - omit the default prop now, correct?

```
titleFormat:
  type: textarea
  label: Title Format

```

But when I create a new project, the textarea field is still empty.

---

<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 26, 2020, 10:07pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/17 "2020-07-26T22:07:52Z")

</div>

I corrected my suggestion

```auto
<?php

class ProjectPage extends Page {
  public static function create(array $props): Page {
    $props['content']['titleformat'] = $props['content']['title'];
    return parent::create($props);
  }
}
```

---

<div class="post-metadata">

**Author:** ![something-strange](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/something-strange/32/8796_2.png) [@something-strange](https://forum.getkirby.com/u/something-strange)\
**Post date:** [July 26, 2020, 10:11pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/18 "2020-07-26T22:11:06Z")

</div>

> [@texnixe](#):
>
> `$props['content']['titleformat'] = $props['content']['title'];`

Hmm, still isn’t working. I read somewhere parent is no longer what the page model is extending? So is this still correct in the model? `return parent::create($props);`

---

<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 26, 2020, 10:12pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/19 "2020-07-26T22:12:11Z")

</div>

No, what you read is that the model must refer to the page itself, not the parent page like before 3.4 (but that has nothing to do with calling `parent::create`.

This is what you are referring to, I guess: [Hook page.create:before, how to edit user input?](https://forum.getkirby.com/t/hook-page-create-before-how-to-edit-user-input/12656/19)

Unless you are on an older Kirby 3 version, in which case you would have to put the create method in the parent page model…

---

<div class="post-metadata">

**Author:** ![something-strange](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/something-strange/32/8796_2.png) [@something-strange](https://forum.getkirby.com/u/something-strange)\
**Post date:** [July 26, 2020, 10:24pm UTC](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898/20 "2020-07-26T22:24:36Z")

</div>

Right, ha, that’s what I was referring to.

So… apparently I am running Kirby 3.3.5 (I just used the Kirby Vue Starterkit, I just assumed I was on the latest version since I started this project the other week).

Knowing I’m on 3.3.5, what should I do? I’m not using any hooks, jus the model extended and blueprint.

`/site/models/project.php`

```
<?php

class ProjectPage extends Page {
  public static function create(array $props): Page {
    $props['content']['titleformat'] = $props['content']['title'];
    return parent::create($props);
  }
}

```

`site/blueprints/pages/project.yml`

```
columns:
  - width: 2/3
    sections:
      rightCol:
        type: fields
        fields:
          titleFormat:
            type: textarea
            label: Title Format

```

Do I need to call the model somewhere / somehow or does Kirby do this under the hood?

[Next page](https://forum.getkirby.com/t/kirby3-blueprint-text-field-dynamic-default-value-from-page-title/18898.md?page=2)
