How to build a URL with representation and params

Hi,

I’m trying to build a URL using the url() function. My URL has parameters and representation, so it looks something like:

https://mysite.com/home.async/color:red/

I use a code like this to generate the URL:

<?= page('home')->url(['params' => ['color' => 'red']]) ?>

Now… how do I add the .async representation there?

Thanks!

There is no method to call a content representation, so you would have to build this manually, and then add the params manually.


page('home')->url() . '.async' . '/color:' . $color
1 Like

Thanks @texnixe! That works (for most cases) and with a page method I can get by.

However, I still think it would be very nice if this functionality could be incorporated into Kirby so that we can call something like page('home')->url('async', [params => [color => 'red']]) and the URL is build with all its necessary parts and checks. Without a function, you quickly run into problems. I for instance had to code an exception for /home (on a multilanguage site), as otherwise it would return https://mysite.com/en.async/color:red and Kirby thinks I’m calling a page called “en” and breaks.

Maybe create a feature request on https://feedback.getkirby.com?

1 Like

Done.

In case somebody lands here wishing for the same feature, go vote: Page URL method to accept a content representation parameter · Kirby Feedback