I am having the same problem as described here , but I definitely need to change the template in the create:after
not in the update:after
hook.
I can change the template in the update hook, so this works:
'file.update:after' => function(Kirby\Cms\File $newFile, Kirby\Cms\File $oldFile){
if($newFile->type()=='video'){
$newFile->update([
'template' => 'video',
'text' => 'videoxxx'
]);
};
}
the exact same code doesn’t work in the create after hook:
'file.create:after' => function(Kirby\Cms\File $file){
if($file->type()=='video'){
$file->update([
'template' => 'video',
'text' => 'video'
]);
};
}
The update of the text field is working, I can see the ‘video’ text in the field, the template somehow does not work…this confuses me, please help <3
Kirby version: 3.9.1
Also there are no other file hooks involved that could override it on my end.
Cheers, Joscha
Is yours a multi-language site like in the thread you linked to?
Yes, and I also tried to loop through the languages with the same outcome.
okay so I now had the time to recreate this in a clean Kirby installation.
It works as long as there is just one language. But in a multilang setup changing the template inside the hook doesn’t work anymore. Should I submit an issue for this?
this is the code:
'hooks' => [
'file.create:after' => function (Kirby\Cms\File $file) {
foreach (kirby()->languages() as $lang) {
$file = $file->update([
'template' => $file->type(),
'text' => 'test',
], $lang->code());
};
}
]
again: 'text' => 'test'
works. Just the template won’t work…
changes nothing unfortunately…
if it helps, here is the setup for quick reproduction.
The hook is inside a plug-in: site/plugins/change-file-template/
Thanks, yes, it just doesn’t work as expected.
Cris
February 10, 2023, 8:39am
10
Just for reference, there’s also another topic about this problem here .
ah right, didn’t see that, thanks!
This issue fixed and will be released 3.9.2 version.