# Collect subpage of page as variable, best practice

**URL:** <https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036>\
**Category:** Questions\
**Tags:** v2\
**Created:** [August 13, 2018, 6:25pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036 "2018-08-13T18:25:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![plagasul](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/plagasul/32/4199_2.png) [@plagasul](https://forum.getkirby.com/u/plagasul)\
**Post date:** [August 13, 2018, 6:25pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036/1 "2018-08-13T18:25:08Z")

</div>

Hello,

If I have:

`$currentEdition = page('editions')->children()->visible()->last();`

What would be the best practice to collect a specific subpage of ` $currentEdition` such as `/exhibitions` ?

Right now I am using find():

`$currentExhibitions = $currentEdition->find('exhibitions');`

…but seems a bit overkill since I know which subpage I am looking for and it is a direct child.

What would be the best practice here?

Thank you

---

<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 13, 2018, 6:47pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036/2 "2018-08-13T18:47:14Z")

</div>

Looks ok to me, unless you want to address the page directly:

```auto
$currentExhibitions = page('edition/exhibitions');

```

---

<div class="post-metadata">

**Author:** ![pedroborges](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pedroborges/32/7038_2.png) [@pedroborges](https://forum.getkirby.com/u/pedroborges)\
**Post date:** [August 13, 2018, 8:35pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036/3 "2018-08-13T20:35:52Z")

</div>

Using `$currentEdition->find('exhibitions')` is not an overkill in that case because the `find` method will look for a direct child of `$currentEdition` first.

The `page` helper also uses `$site->children()->find($uri)` under the hood.

Use whatever you find nicer!

---

<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 13, 2018, 8:39pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036/4 "2018-08-13T20:39:05Z")

</div>

> [@pedroborges](#):
>
> will look for a direct child of `$currentEdition` first.

If you pass a UID to `find()`, Kirby will only look for direct children, never further down the tree.

---

<div class="post-metadata">

**Author:** ![pedroborges](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pedroborges/32/7038_2.png) [@pedroborges](https://forum.getkirby.com/u/pedroborges)\
**Post date:** [August 13, 2018, 8:51pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036/5 "2018-08-13T20:51:22Z")

</div>

That’s correct, it will only further if there’s a slash relative to the parent page where `find` was called from.

---

<div class="post-metadata">

**Author:** ![plagasul](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/plagasul/32/4199_2.png) [@plagasul](https://forum.getkirby.com/u/plagasul)\
**Post date:** [August 13, 2018, 8:52pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036/6 "2018-08-13T20:52:58Z")

</div>

Thank you both.

I was wondering if perhaps there could be something like:

```auto
page($currentExhibition . '/exhibitions');

```

---

<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 13, 2018, 8:55pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036/7 "2018-08-13T20:55:24Z")

</div>

> [@plagasul](#):
>
> page($currentExhibition . ‘/exhibitions’);

```auto

page($currentExhibition->uid() . '/exhibitions');

```

would be possible. With the downside that it will throw an error. if `$currentExhibition` doesn’t exist.

This here:

```auto
$currentExhibitions = $currentEdition->find('exhibitions');

```

has the same. problem, though. It should actually be:

```auto
if($currentEdition) {
  $currentExhibitions = $currentEdition->find('exhibitions');
}

```

---

<div class="post-metadata">

**Author:** ![plagasul](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/plagasul/32/4199_2.png) [@plagasul](https://forum.getkirby.com/u/plagasul)\
**Post date:** [August 13, 2018, 9:25pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036/8 "2018-08-13T21:25:09Z")

</div>

You are right, thank you.

Between

```auto
page($currentExhibition->uid() . '/exhibitions');

```

and

```auto
$currentEdition->find('exhibitions');

```

…is there any notable difference ?

---

<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 13, 2018, 9:40pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036/9 "2018-08-13T21:40:02Z")

</div>

No, as @pedroborges already pointed out, the page helper uses find internally anyway. So go with what you like best.

---

<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, 5:26pm UTC](https://forum.getkirby.com/t/collect-subpage-of-page-as-variable-best-practice/11036/10 "2025-02-06T17:26:27Z")

</div>


