# Routes: return template to fake a page - running into error

**URL:** <https://forum.getkirby.com/t/routes-return-template-to-fake-a-page-running-into-error/6081>\
**Category:** Questions\
**Tags:** v2\
**Created:** [December 17, 2016, 3:28pm UTC](https://forum.getkirby.com/t/routes-return-template-to-fake-a-page-running-into-error/6081 "2016-12-17T15:28:49Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [December 17, 2016, 3:28pm UTC](https://forum.getkirby.com/t/routes-return-template-to-fake-a-page-running-into-error/6081/1 "2016-12-17T15:28:49Z")

</div>

Hi guys,

for a plugin, I am trying to set up routes for non existing pages that return templates located within the plugin:

```php
$kirby->set('route', [
  'pattern' => $passport->url() . '/(trip|home)/(:num)',
  'action' => function($type, $id) {
    ...

    return \tpl::load(kirby()->registry->get('template', 'passport-trip'), ['trip' => $trip]);
  }
]);

```

However I get the following error:

```auto
Catchable fatal error: Argument 1 passed to Kirby::render() must be an instance of Page, boolean given, called in /Users/nhoffmann/Development/passport/kirby/kirby/component/response.php on line 25 and defined in /Users/nhoffmann/Development/passport/kirby/kirby.php on line 558

```

I know that the template is found and loaded correctly, cause when I omit passing through $trip, I see half of the template until the error that $trip cannot be found.

I cannot wrap my brain around the error. Any ideas, previous experiences, solutions from anyone?

p.s. and yes I really would not like to put page placeholder into the content folder as this would make the plugin install more complicated

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [December 18, 2016, 7:48am UTC](https://forum.getkirby.com/t/routes-return-template-to-fake-a-page-running-into-error/6081/2 "2016-12-18T07:48:09Z")

</div>

When return don’t you need to return a site()-\>visit? Can you use echo instead of return?

---

<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:** [December 18, 2016, 10:52am UTC](https://forum.getkirby.com/t/routes-return-template-to-fake-a-page-running-into-error/6081/3 "2016-12-18T10:52:31Z")

</div>

What actually did work is to `echo` it and then just `return false`.  
It is quite the hack, I guess, and I will see what other problems I will run into with it.

So if anyone has a smoother idea for pages without content files, let me know.

---

<div class="post-metadata">

**Author:** ![fvsch](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/fvsch/32/15908_2.png) [@fvsch](https://forum.getkirby.com/u/fvsch)\
**Post date:** [December 18, 2016, 11:58am UTC](https://forum.getkirby.com/t/routes-return-template-to-fake-a-page-running-into-error/6081/4 "2016-12-18T11:58:56Z")

</div>

Kirby expects a Response for route actions:

> An action must either return a page object, a response object, redirect to a different URL or exit the code execution by returning false.  
> [https://getkirby.com/docs/developer-guide/advanced/routing](https://getkirby.com/docs/developer-guide/advanced/routing)

The logic is a bit more precise if you look at the `Kirby\Component\Response` class, which handles the “hey, we want to make a response out of this mixed input” use case. If you return a string, it will treat it as a page uri:

```php
if(is_string($response)) {
  return $this->kirby->render(page($response));
}

```

That’s probably a bad case of tight coupling between this class and a behavior that some Kirby helpers and/or internals expected. ^^ (A more agnostic class would return `new Response($response)` in that situation.)

Anyway, the clean way to return a HTML response from a route action when the action itself provides the full HTML result would be:

```php
function(…) {
  $html = ...;
  return new Response($html);
}

```

You can also handle different HTTP statuses, with e.g; `return new Response($html, 'html', 404);`

---

<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:** [December 18, 2016, 12:01pm UTC](https://forum.getkirby.com/t/routes-return-template-to-fake-a-page-running-into-error/6081/5 "2016-12-18T12:01:35Z")

</div>

Thanks a lot, completely overlook that. Returning with Response works like a charm.

---

<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:50pm UTC](https://forum.getkirby.com/t/routes-return-template-to-fake-a-page-running-into-error/6081/6 "2025-02-06T16:50:34Z")

</div>


