Is there any chance to change the content off a page in a controller - just for the view?

My idea is it to change e.g. the headline of a page just for this specific call.

$page->headline('new headline');

or

$page->headline()->set('new headline');

or

$page->content('headline', 'new headline');

I want to use this for using the text file as default values and update the content if necessary.

Greetings and thanks for you ideas :slight_smile:

You can update field values via $page->update(); but I don’t get why you’ld want to do that in a controller?

Let’s say you have a page with a availability info of a service - usually this service is running but before you render the page you call an API to check it if the API is running or not wit the intention to change the value if not…

Ok, I wouldn’t store the availability as a field value, but retrieve it from the endpoint for each call (and perhaps cache it for a certain amount of time). But be aware that this could slow down render time.

Or maybe even handle this in the front-end via AJAX if is not “mission-critical”. Then you could still leverage server-side caching.

You’re right it is more a historic ‘issue’ because authors wanted to change the message. Yeah, but I can return a variable with the updated content…

Sorry but I’m checking all the changes to v3 and it is a lot behind the curtain…

You could set 2 text fields: successmessage and failmessage that authors can alter.

Depending on the result of the endpoint, you can choose which message should be shown (be it in the backend or frontend).

Yes, might be an other solution…

I’m checking: https://getkirby.com/docs/guide/templates/page-models

Maybe I can have an even better solution…

Yes is is - an even more clean…