Can't access page uri

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.

<?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

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

<?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.

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

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