I don’t think you’ll get any useful answer without elaborating what you want to achieve. Cause this all doesn’t make a lot of sense to me (calling the render() method in an update hook.
Why should the home page has new content? This is the site update hook, so the content changed is of site not of home.
Okay let’s go deeper into my aim: I have fields over my pages and site. The values of this fields needs to be saved in presence of its content. (On update - with a special condition)
I decide to render the current page on save and it works well. But if the user change something on the side, any page needs to be rerendered with the new values (in this case: the homepage).
But how? I need something like render a page with an injection of the new side variables or a side:update:after:after hook.
But how would the other pages, e.g. home, be already updated in site.update:after? Wouldn’t you need to do $site->homePage()->update() first inside site.update:after?
I think you are running into a race condition. If you sleep briefly before rendering, then it seems to work. But I don’t think this is very stable. And you would not be able to use the cache, unless you flush it manually.
Let say i like to create custom CSS, that needs to be created, when the visitor call the page.
I send fetch_vars to the page. If this fetch_var presents, it starts fetching things. And at the end of the page, it writes the fetched values to a file.
For now i don’t need the HTLM output. But it could be nice, if i recieving there the fetched vars. So i don’t need to make a call inside the pages end.
No, of course not, it wouldn’t make sense, at least not considering how Kirby works.
It’s hard to judge without knowing the details, but rendering an entire page just to write some CSS to a file seems somehow wrong and not very resource efficient.
The more elegant solution is, to using controllers:
'controllers' => [
'site' => function () {
return [
'foo' => "No value given"
];
}
],
'site.update:after' => function ($newSite, $oldSite) {
$foo = $newSite->homepage()->controller()['foo'];
// Write $foo or pin it on the hat
},
In the template you could use:
<?php $foo = site()->foo()->isTrue() ? "Foo is True" : "Foo is False"; ?>
I just mention it, in case some other people likes to take some samples of code to make something great with kirby. To use a class with methods is not a (or the) problem.
In my last posts i shown two examples.
$foo is just a variable to set, when you need it.
$foo is a class, that is defined in the controller. (Sorry, i forgot to give the code of the initializing the class):
'controllers' => [
'site' => function () {
return [
'foo' => new FooClass()
];
}
],