Routing Array Error

#1

Hello I am referring to an older topic of mine:

I am currently updating my website from Kirby 2 to Kirby 3. I tried to change my routing with the new syntax. But I only get errors.

Here is what I want to achieve:

  • I am using ajax to load a page content into an overlay
  • I also want to get to this state with a direct URL access

This is how my routing looks like:

<?php

return [
	'routes' => [
	    [
	      'pattern' => 'projects/(:any)',
		  'action' => function($modal) {
				$kirby = kirby();
				$page = page('projects')->find($modal);
				
				if($page) {
					$html = $kirby->render($page);
					return new Response($html);
				} else {
					$page = site()->errorPage();
					site()->visit($page);
				}	
			},
			'method' => 'POST'
	    ],
	    [
		    'pattern' => 'projects/(:any)',
			'action' => function($modal) {
				$page = page('projects')->find($modal);
				if($page) {
					$data = array('modal' => $page->url());
					return array('home', $data);
				} else {
					$page = site()->errorPage();
					return site()->visit($page);
				}
			}
		]
	]
];

When I enter the url I only get a blank page with the following line:
["home",{"modal":"http:\/\/localhost:8888\/studio_oui_r\/projects\/test"}]

#2

Yep, an array is now returned as a JSON array, ran into that recently as well, but can’t find anything in the docs or my brain how to solve this to return additional data to the page.

#3

Thanks for your answer. Oh no. So there is currently no solution/workaround for this? :frowning:

#4

I’m not saying that, I just don’t know.

#5

Hi @texnixe. Just wanted to ask if you could find a solution for this? … I didn’t get any further on this one. Maybe there is a solution now :slight_smile:

#6

Yes, can be achieved with $page->render().

1 Like
#7

oh nice! I will give it a try. Thanks for this!