# Creating page that you never intend to navigate to

**URL:** <https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101>\
**Category:** Questions\
**Tags:** v3\
**Created:** [November 20, 2020, 6:41pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101 "2020-11-20T18:41:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [November 20, 2020, 6:41pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/1 "2020-11-20T18:41:54Z")

</div>

I’m surprised I haven’t considered this before, maybe I never addressed it properly. I will have a collection of pages that each hold a single location (name, address, city, etc.). I will then use that collection of pages to allow the user to select a location (pages field type). I’ll never want someone to navigate to one of those location pages - they will only be a collection for internal use. What’s the proper setup here? Do I leave those locations as Drafts? Yeah. Drafts. Right? Will that prevent them from having their own URL?

---

<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:** [November 20, 2020, 7:13pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/2 "2020-11-20T19:13:43Z")

</div>

I usually make them unlisted and then use routes to redirect such URLs to the error page. Same procedure as for subpages that only deliver the content for their parent page.

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [November 20, 2020, 7:15pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/3 "2020-11-20T19:15:56Z")

</div>

I see. Thanks.

---

<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:** [November 20, 2020, 7:27pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/4 "2020-11-20T19:27:09Z")

</div>

Drafts would be an option, as they can only be accessed by logged in users (and you don’t have to think about the additionla route), but it somehow doesn’t feel right, at least not to me. Plus you then cannot use the draft state to differentiate published locations from non-published locations in your queries.

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [November 20, 2020, 7:31pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/5 "2020-11-20T19:31:39Z")

</div>

But on the positive side the client wouldn’t need to set a state (which clients tend to forget). On this task I’m struggling with setting the proper query to these locations? I’m using a pages field and filtering based on the ‘location’ template, but nothing shows up. Something must be amiss here.

```
camp_loc:
  label: Location
  type: pages
  query: page.index.filterBy('template', 'in', ['location'])
  max: 1
```

---

<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:** [November 20, 2020, 7:33pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/6 "2020-11-20T19:33:34Z")

</div>

Should be `intendedTemplate()` if the page has no template. `template` only works if there is a `location.php` template in` /site/templates`, which doesn’t make sense if the page is not accessible.

> [@thewebprojects](#):
>
> But on the positive side the client wouldn’t need to set a state (which clients tend to forget).

You could automatically set the state to published using a hook or even a model.

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [November 20, 2020, 7:36pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/7 "2020-11-20T19:36:54Z")

</div>

Oh hell… I was thinking of a blueprint as a template. Right. The locations have no template. What’s this new devilry, this `intendedTemplate()` ? So that assumes the template would be whatever the blueprint is named. Interesting.

---

<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:** [November 20, 2020, 7:37pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/8 "2020-11-20T19:37:43Z")

</div>

> [@thewebprojects](#):
>
> new devilry, this `intendedTemplate()`

It’s a very old devil, this differentiation already existed in Kirby 2.

The `intendedTemplate` is the template the page would use based on the text file name if there was a template. The blueprint is responsible for setting the content file name.

This has always been a point for confusion because as a user you are told to select a template when creating a page whereas in reality you select the blueprint.

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [November 20, 2020, 7:40pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/9 "2020-11-20T19:40:32Z")

</div>

True dat. Good to know. Useful.

I know we’re getting way off topic now, but could you point me to some additional info regarding automatically setting a new page state to unlisted or published. Does that hook happen immediately upon adding the page or on save?

---

<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:** [November 20, 2020, 7:45pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/10 "2020-11-20T19:45:05Z")

</div>

> [@thewebprojects](#):
>
> Does that hook happen immediately upon adding the page or on save?

Depends on the hook you use. `page.create:after` hook would publish the page right after creation. `page.update:after` would publish the page after saving.

There are a few examples somewhere around here. Basically,

```auto
return [
    'hooks' => [
        'page.create:after' => function ($page) {
   	        $page->changeStatus('unlisted');
        }
    ]
]

```

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [November 20, 2020, 7:47pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/11 "2020-11-20T19:47:21Z")

</div>

Perfect! As always, thanks for your insight.

---

<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:** [November 20, 2020, 7:57pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/12 "2020-11-20T19:57:01Z")

</div>

The - imo better - alternative to hooks is using a page model, particularly, if you only need this for only a single or few page types:

```auto
<?php

use Kirby\Cms\Page;
class LocationPage extends Page
{
   public static function create(array $props) {
        $props['draft'] = false;
        return parent::create($props);
   }
}

```

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [November 20, 2020, 7:58pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/13 "2020-11-20T19:58:50Z")

</div>

You don’t see me. I hide from code that’s too fancy. My eyes are shut. That means no one can see me.

---

<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:** [November 20, 2020, 8:00pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/14 "2020-11-20T20:00:28Z")

</div>

😂

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [November 20, 2020, 8:01pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/15 "2020-11-20T20:01:38Z")

</div>

I’m trying and failing at using that intendedTemplate() business in my query for pages. Can you provide an example, say I’m looking for all pages that use the blueprint location.

---

<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:** [November 20, 2020, 8:04pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/16 "2020-11-20T20:04:13Z")

</div>

> [@thewebprojects](#):
>
> `page.index.filterBy('template', 'in', ['location'])`

Should be

```auto
page.index.filterBy('intendedTemplate', 'location')

```

The `in` filter is not necessary if you only check against one value. But I’m not sure about the `page.index` part. That only gets the page tree of the current page. So it depends from where you are querying.

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [November 20, 2020, 8:07pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/17 "2020-11-20T20:07:08Z")

</div>

That doesn’t work, but I think I might know why. Those location pages are sibling pages. Consider the attached screenshot. I’m on a camp page, but want to get a location from a location page, which is a child of Summer Camps.

 ![ss](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/c/c45fcc97e8c11ca5af0dd0cbf0bdcd5f39558658.jpeg)

 ![ss](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/6/6167aca11afbb4f1ab865fbff59c7f8361bdc5a9.jpeg)

---

<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:** [November 20, 2020, 8:10pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/18 "2020-11-20T20:10:08Z")

</div>

That what I thought, so you should probably find the page by direct path or relatively:

```auto
page.parent.children.filterBy('intendedTemplate', 'location')

```

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [November 20, 2020, 8:12pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/19 "2020-11-20T20:12:11Z")

</div>

That did 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:** [November 20, 2020, 8:12pm UTC](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101/20 "2020-11-20T20:12:47Z")

</div>

But seriously, consider the page model. Then Kirby doesn’t have to do two things (create the page and then change it again in the hook).

[Next page](https://forum.getkirby.com/t/creating-page-that-you-never-intend-to-navigate-to/20101.md?page=2)
