# Cannot get Page Model to work

**URL:** <https://forum.getkirby.com/t/cannot-get-page-model-to-work/31166>\
**Category:** Questions\
**Tags:** v4\
**Created:** [March 21, 2024, 8:45am UTC](https://forum.getkirby.com/t/cannot-get-page-model-to-work/31166 "2024-03-21T08:45:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominiklaube](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/dominiklaube/32/13863_2.png) [@dominiklaube](https://forum.getkirby.com/u/dominiklaube)\
**Post date:** [March 21, 2024, 8:45am UTC](https://forum.getkirby.com/t/cannot-get-page-model-to-work/31166/1 "2024-03-21T08:45:22Z")

</div>

Unfortunately I can’t get the page model to work. I don’t get what I’m doing wrong here. Any ideas?

**/site/models/contact.php**

```auto
<?php

class ContactPage extends Page
{
    public function foo(): string
    {
        return 'Foo';
    }
}

```

**/site/templates/contact.php**

```auto
<?php var_dump($page->foo()); ?>

```

**Result**

```auto
object(Kirby\Content\Field)#387 (1) { ["foo"]=> NULL }

```

Kirby 4.1.2

---

<div class="post-metadata">

**Author:** ![ahmetbora](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahmetbora/32/11671_2.png) [@ahmetbora](https://forum.getkirby.com/u/ahmetbora)\
**Post date:** [March 21, 2024, 8:57am UTC](https://forum.getkirby.com/t/cannot-get-page-model-to-work/31166/2 "2024-03-21T08:57:54Z")

</div>

Make sure that contact page have `contact.txt` content file: `/content/contact-us/contact.txt`

---

<div class="post-metadata">

**Author:** ![dominiklaube](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/dominiklaube/32/13863_2.png) [@dominiklaube](https://forum.getkirby.com/u/dominiklaube)\
**Post date:** [March 21, 2024, 9:09am UTC](https://forum.getkirby.com/t/cannot-get-page-model-to-work/31166/3 "2024-03-21T09:09:57Z")

</div>

Thanks for the fast response @ahmetbora. Yes, that should be ok already - the filename is `contact.de.txt`.  
Just tested the output of `$page->intendedTemplate()->name()` on the page and it returns `contact`.  
Maybe there is more to consider?

---

<div class="post-metadata">

**Author:** ![ahmetbora](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahmetbora/32/11671_2.png) [@ahmetbora](https://forum.getkirby.com/u/ahmetbora)\
**Post date:** [March 21, 2024, 9:38am UTC](https://forum.getkirby.com/t/cannot-get-page-model-to-work/31166/4 "2024-03-21T09:38:31Z")

</div>

So your setup is correct and should be work fine. I’ve tested on 4.1.2 and works as expected. Do you have any plugins? Seems some setup broke the calling models.

---

<div class="post-metadata">

**Author:** ![dominiklaube](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/dominiklaube/32/13863_2.png) [@dominiklaube](https://forum.getkirby.com/u/dominiklaube)\
**Post date:** [March 21, 2024, 9:51am UTC](https://forum.getkirby.com/t/cannot-get-page-model-to-work/31166/5 "2024-03-21T09:51:45Z")

</div>

You were right, the problem is caused by a plugin. Inside the route function it used `$kirby->page();`. This caused the wrong page model to be loaded. At the moment I’m not sure how to workaround this.

```auto
    'routes' => function ($kirby) {
        ...

        $kirby->page('pageid');
       
        ...

```

---

<div class="post-metadata">

**Author:** ![ahmetbora](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahmetbora/32/11671_2.png) [@ahmetbora](https://forum.getkirby.com/u/ahmetbora)\
**Post date:** [March 21, 2024, 10:15am UTC](https://forum.getkirby.com/t/cannot-get-page-model-to-work/31166/6 "2024-03-21T10:15:44Z")

</div>

Hmm, could you share which plugin? Maybe I can check or help with fix it.

---

<div class="post-metadata">

**Author:** ![dominiklaube](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/dominiklaube/32/13863_2.png) [@dominiklaube](https://forum.getkirby.com/u/dominiklaube)\
**Post date:** [March 21, 2024, 10:25am UTC](https://forum.getkirby.com/t/cannot-get-page-model-to-work/31166/7 "2024-03-21T10:25:33Z")

</div>

It is not public. In general it is a lightweight plugin for managing redirects. Maybe you have a fast idea for a rewrite?

```auto
'routes' => function ($kirby) {
        $routes = [];

        if ($kirby->page('redirects')) {
            foreach($kirby->page('redirects')->redirects()->toStructure() as $redirect) {
                $routes[] = [
                    'pattern' => $redirect->from()->toString(),
                    'action' => function () use ($redirect) {
                        go($redirect->to()->toUrl(), $redirect->statusCode()->toInt(301));
                    }
                ];
            }
        }

        return $routes;
    }

```

---

<div class="post-metadata">

**Author:** ![dominiklaube](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/dominiklaube/32/13863_2.png) [@dominiklaube](https://forum.getkirby.com/u/dominiklaube)\
**Post date:** [March 21, 2024, 12:03pm UTC](https://forum.getkirby.com/t/cannot-get-page-model-to-work/31166/8 "2024-03-21T12:03:49Z")

</div>

I found fast workaround, not elegant but maybe ok

```auto
$kirbyClone = clone $kirby;

```

then use `$kirbyClone` instead of `$kirby`
