# Can't access page uri

**URL:** <https://forum.getkirby.com/t/cant-access-page-uri/15685>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 17, 2019, 3:25pm UTC](https://forum.getkirby.com/t/cant-access-page-uri/15685 "2019-09-17T15:25:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oliver](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/oliver/32/13482_2.png) [@Oliver](https://forum.getkirby.com/u/Oliver)\
**Post date:** [September 17, 2019, 3:25pm UTC](https://forum.getkirby.com/t/cant-access-page-uri/15685/1 "2019-09-17T15:25:04Z")

</div>

Hi there, working with good old Kirby 2.

Filtering images from an image field (images plugin) with a `project.php` controller for my `project.php` template, and have no issues so far, also have a different installation where everything is working as expected.

However, in one case, I’m having a strange issue when `$galleryType == 'grid'`. Here I’m querying the images from the field but getting `Undefined variable: uri`.

What is strange is that it works if I manually set the uri in:

`$val = implode(", ", page($uri)->galleryimages()->yaml());`

to `projects/nosted` in this case:

`$val = implode(", ", page('projects/nosted')->galleryimages()->yaml());`

Running Kirby 2.5.12 on PHP 7.2.

```auto
<?php

return function($site, $pages, $page) {

	// Gallery Field Image Filtering

	$uri = $page->uri();

	$galleryType = $page->gallerytype();

	if($galleryType == 'alternating') {
		$images = $page->galleryimages()->yaml();
	} elseif($galleryType == 'grid') {
		$images = $page->images()->filter(function($image) {
			$val = implode(", ", page($uri)->galleryimages()->yaml());
			$filenames = explode(", ", $val);
			return in_array($image->filename(), $filenames);
		});
	}

	return compact(
		'galleryType',
		'images'
	);

};

```

Any thoughts on what might be the issue?

Best, Oliver

---

<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:** [September 17, 2019, 3:48pm UTC](https://forum.getkirby.com/t/cant-access-page-uri/15685/2 "2019-09-17T15:48:22Z")

</div>

Where’s the point of getting the page from the URI if you might as well use the `$page` variable?

```auto
<?php

return function($site, $pages, $page) {

	// Gallery Field Image Filtering

	$galleryType = $page->gallerytype();

	if($galleryType == 'alternating') {
		$images = $page->galleryimages()->yaml();
	} elseif($galleryType == 'grid') {
		$images = $page->images()->filter(function($image) use($page) {
			$val = implode(", ", $page->galleryimages()->yaml());
			$filenames = explode(", ", $val);
			return in_array($image->filename(), $filenames);
		});
	}

	return compact(
		'galleryType',
		'images'
	);

};

```

The reason why your code doesn’t work is that you would have to pass the `$uri` variable to the anonymous function in the same way I now pass the `$page` variable.

---

<div class="post-metadata">

**Author:** ![Oliver](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/oliver/32/13482_2.png) [@Oliver](https://forum.getkirby.com/u/Oliver)\
**Post date:** [September 17, 2019, 3:52pm UTC](https://forum.getkirby.com/t/cant-access-page-uri/15685/3 "2019-09-17T15:52:04Z")

</div>

Haha, yes, you’re absolutely right…  
It works, thanks so much!

Think I’ll call it a day, best to you 😉

---

<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:22pm UTC](https://forum.getkirby.com/t/cant-access-page-uri/15685/4 "2025-02-06T17:22:44Z")

</div>


