Create a page object like the template

In a route I do this:

id and language are post variables from the route.

$page= page( get('id') )->content( get('language') );

I know it’s a page content object but I call it $page anyway to show my problem.

echo $page->title(); // Works
echo $page->uri(); // Fail

In the template I can do this:

echo $page->title(); // Works
echo $page->uri(); // Works

Is there a simple way to do the same with a “created” kind of page object? It needs to take the language into account so that the uri is language specific.

The content object has no uri method…, only the page object. You can get all the fields via the content object, but not page methods.

To show you what I mean, see what you get when you add this to your template:

a::show($page->content()->toArray());

Yes, but if I use the $page object it’s not aware of the language. To not mess around too much I write the question in an alternative way. Hopefully it will make things easier?

The question in an alternative way

I leave all my own solutions out and just add what I have.

Available in the route

What I have:

$id = 'about/contact';
$language = 'sv';

Result

echo $page->title(); // Kontakt
echo $page->uri(); // om/kontakt

Do you think there is a good way to achive this? :slight_smile:

You can pass a language code to the uri() method: https://getkirby.com/docs/cheatsheet/page/uri

For me this is still unsolved. I guess there is no quickfix for it then. I’ll probably need to dig deeper into the core to find the answer. :slight_smile:

You probably wonder, why the heck do I need that for!? :wink:

Maybe this is a clew:

github.com/jenstornell/kirby-reveal/blob/master/routes.php

// A template has these classes
$page = page( get('id') )->content( get('language') );
$pages = site()->children();
$site = site();	

// I need to include these variables as well
$language = get('language');
$uri = get('uri');

With this workaround, a language always need to be sent as argument to get the correct value:

<?php echo $page->uri( $language ) ?>

I have not released my Reveal plugin in public yet, but it does not have to do with I’m being stuck with it. I simply have much more to do because I started what the world seems to call a “Limited company” ( http://devonera.se). :smiley:

That means I need to make money as well, not only plugins. :wink: