# Page-\>create() does not return object with correct template

**URL:** <https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008>\
**Category:** Questions\
**Tags:** v2\
**Created:** [August 18, 2016, 10:31am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008 "2016-08-18T10:31:38Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [August 18, 2016, 10:31am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/1 "2016-08-18T10:31:38Z")

</div>

a ‘dashbox’ is a child (=subpage) of ‘dashboard’.  
both template and blueprint files exist and are valid yml.  
kirby version is 2.3.0.

i [create](https://github.com/getkirby/kirby/blob/master/core/page.php#L1151) a new page with an template like this…

```
// $dashboard is root folder to create stuff.
$newUriForDashbox = $dashboard->uri() . DS . $newUsername;
$dashbox = $dashboard->create($newUriForDashbox, 'dashbox', [
    'user' => $user->username(), 
    'title' => $newUsername,
    'erstelltam' => date('c'),
    'erstelltvon' => $user->username(),
    'erstelltvisitor' => visitor::ip().' '.visitor::userAgent(),
    'finalisiert' => false
]);
echo $dashbox->template(); // = default, but dashbox was expected

```

the file is created correctly, path and filename (matching template name).  
but the returned object is not the one created, but an ‘default’ page.

when i get the object manually again after creating like above all is well.

```
$dashbox = $pages->find($newUriForDashbox);
echo $dashbox->template(); // = dashbox
echo $dashbox->intendedTemplate(); // = content of $newUsername (=foldername)

```

whats going wrong when calling create()?

---

<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:** [August 18, 2016, 10:45am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/2 "2016-08-18T10:45:06Z")

</div>

I think you should use the `$pages->create()` method instead of the static method `$page->create()`:

````auto
$dashbord = page('dashboard');
$dashbox = $dashboard->children()->create($newUsername, 'dashbox', [
    'user' => $user->username(), 
    'title' => $newUsername,
    'erstelltam' => date('c'),
    'erstelltvon' => $user->username(),
    'erstelltvisitor' => visitor::ip().' '.visitor::userAgent(),
    'finalisiert' => false
]);
```
````

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [August 18, 2016, 11:03am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/3 "2016-08-18T11:03:26Z")

</div>

resulting dashbox is still of 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:** [August 18, 2016, 11:20am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/4 "2016-08-18T11:20:59Z")

</div>

Yeah, you are right, this seems really weird. I just tested this and found that with one template I used, the correct template was shown, but with all other templates it failed, showing “default” instead.

While `$dashboard->intendedTemplate()` shows the uid, which is not correct either.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [August 18, 2016, 11:33am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/5 "2016-08-18T11:33:22Z")

</div>

i have 41 blueprints/templates. could this be an issue? like memorywise?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [August 18, 2016, 11:33am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/6 "2016-08-18T11:33:56Z")

</div>

most of my templates have a ‘-’ (minus) within their filename.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [August 18, 2016, 11:36am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/7 "2016-08-18T11:36:46Z")

</div>

maybe kirby-\>registry is somehow broken by my code? [https://github.com/getkirby/kirby/blob/master/core/page.php#L1009](https://github.com/getkirby/kirby/blob/master/core/page.php#L1009)

---

<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:** [August 18, 2016, 11:36am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/8 "2016-08-18T11:36:49Z")

</div>

I don’t think so, I tested this with about 12 - 18 blueprints/templates, none of which had any special characters in their filenames. But maybe we should test with a fresh starterkit first.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [August 18, 2016, 11:41am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/9 "2016-08-18T11:41:43Z")

</div>

i think i encountered something similar before. i did forget to create the template file and only had the blueprint. then the create function did not work either. could it be that i have a missing (check, seems not) or broken template/blueprint? my buleprints are (almost) valid yaml just check again. some contain a regex passage like this which is NOT (edited) accepted by yaml validators.

```
telefon:
  width: 1/3
  label: Telefon
  type: tel
  required: true
  help: Bitte geben Sie Telefon und Faxnummern komplett mit Vorwahl, jedoch ohne Sonderzeichen wie z.B. Klammern oder Punkte ein.
  validate:
    match: "/^\d[\d]+\d$/"
```

---

<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:** [August 18, 2016, 11:45am UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/10 "2016-08-18T11:45:47Z")

</div>

I just tested this in a fresh starterkit with the available blueprint/template pairs and it worked perfectly, so the question is why it does not work in the other cases, in the other project where I tested this first, all blueprint/template pairs were available as well and nothing special in yaml.

Have you tried without the validate option?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [August 18, 2016, 12:02pm UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/11 "2016-08-18T12:02:36Z")

</div>

it did work before with the vaidate. today i just added two new templates/blueprints (with no regex) and now its broken. i checked my repo not much else changed. does kirby cache this ‘registry’ between session?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [August 18, 2016, 12:56pm UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/12 "2016-08-18T12:56:46Z")

</div>

why does getting the template directly after creating it work with find() but not when using the page() function? page() is used for the return value of create(), right?

```
 // HERE: create page omitted then...
 $dashbox = kirby()->site()->page($newUriForDashbox);
 echo '1:'.$dashbox->template(); // = default, which is wrong. should be 'dashbox'
 $dashbox = $pages->find($newUriForDashbox);
 echo '2:'.$dashbox->template(); // = dashbox, which is right
```

---

<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:** [August 18, 2016, 1:05pm UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/13 "2016-08-18T13:05:21Z")

</div>

But you said above, that even then the `$page->intendedTemplate()` method does not output the intended template but the page uid? While it should output the name of the text file, not the foldername.

I think the problem must be something else, as it all works perfectly as it should with a fresh starterkit. Only I have no idea at the moment, what could be causing this issue. Maybe @lukasbestle to the rescue?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [August 18, 2016, 1:09pm UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/14 "2016-08-18T13:09:44Z")

</div>

mabe because of this?

> <https://github.com/getkirby/kirby/blob/master/core/page.php#L1100>

becauses its called here:

> <https://github.com/getkirby/kirby/blob/master/core/page.php#L1161>

---

<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:** [August 18, 2016, 1:14pm UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/15 "2016-08-18T13:14:02Z")

</div>

No, this is the page method:

```auto
/**
   * Returns the name of the content text file / intended template
   * So even if there's no such template it will return the intended name.
   *
   * @return string
   */
  public function intendedTemplate() {
    if(isset($this->cache['intendedTemplate'])) return $this->cache['intendedTemplate'];
    return $this->cache['intendedTemplate'] = $this->content()->exists() ? $this->content()->name() : 'default';
  }

```

And the text files do get named correctly …

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [August 18, 2016, 1:22pm UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/16 "2016-08-18T13:22:17Z")

</div>

using children()-\>create() calls static page::create, right?

> <https://github.com/getkirby/kirby/blob/master/core/children.php#L41>

about the intendedTemplate, maybe cache need refresh after page create?

> <https://github.com/getkirby/kirby/blob/master/core/page.php#L724>

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:55pm UTC](https://forum.getkirby.com/t/page-create-does-not-return-object-with-correct-template/5008/17 "2025-02-06T16:55:26Z")

</div>

Archived on February 6, 2025, 4:55pm UTC


