Get page html by uri?

Is there a function similar to this?

echo $page->find('my/page/id')->html();

The result of it should be the full page html.

The alternative would be to run cURL, but it would probably be much faster if it was possible to get it “from the inside”.

If it does not exist, would it be a good thing to add? Is there another better way than using cURL to get a page by url html result?

You can achieve something like this with a combination of $site->visit() and $kirby->render().

Take a look at how the StaticBuilder plugin by @fvsch does it. I don’t know however if that would work inside another template as $site->visit() might break the state of the current page.

This works for me… :slight_smile:

<?php
$kirby = new Kirby();
echo $kirby->render( page( $id ) );
?>

I don’t know if I need to use visit for something? Seems to work anyway.

Great that it’s working for you.

1 Like

And I changed my mind. I had trouble to get the render function work with multi languages so I managed to use visit instead. I was inside a route so this worked (in the action):

return site()->visit( $id, $language); ?>

I think visit is needed if you want $site->activePage() and $page->isActive() to work.

1 Like