Replies: 7 comments
-
$view->on(View::EVENT_BEFORE_RENDER, function (ViewEvent $event) {
$view = $event->sender;
$ext = pathinfo($event->viewFile, PATHINFO_EXTENSION);
if (isset($view->renderers[$ext])) {
if (!is_object($view->renderers[$ext])) {
$view->renderers[$ext] = Yii::createObject($view->renderers[$ext]);
}
/** @var ViewRenderer $renderer */
$renderer = $view->renderers[$ext];
$event->output = $renderer->render($view, $event->viewFile, $event->params);
} else {
$event->output = $view->renderPhpFile($event->viewFile, $event->params);
}
$view->afterRender($event->viewFile, $event->params, $event->output);
$event->isValid = false;
}); or return [
...
'components' => [
'view' => [
'class' => View::class,
'on ' . View::EVENT_BEFORE_RENDER => function (ViewEvent $event) {
...
}
],
],
]; |
Beta Was this translation helpful? Give feedback.
-
easy way: is set $view->renderFile($viewFile, new ArrayObject($params), $context); |
Beta Was this translation helpful? Give feedback.
-
Both looks promising. i could do it locally, but do you think it would be framework improvement? |
Beta Was this translation helpful? Give feedback.
-
@papppeter "easy way" is popular native solution, something like this using in reactive JS to detect variable changes. Also, you can do it by render behaviour or extend renderer and override |
Beta Was this translation helpful? Give feedback.
-
@WinterSilence thanks! i will try it out. Should i close this issue? |
Beta Was this translation helpful? Give feedback.
-
@papppeter as you wish, I'm not repo owner (: Do you see discussions? |
Beta Was this translation helpful? Give feedback.
-
Converted it to discussion. |
Beta Was this translation helpful? Give feedback.
-
What steps will reproduce the problem?
Subscribe to View::class, View::EVENT_BEFORE_RENDER
try to add an extra parameter
What is the expected result?
to be able to adjust params
What do you get instead?
params is not extended because it is not used as a reference
Suggestion
it would be nice if i could add a flag to ViewEvent if i would like to use params, and viewFile as a reference, or if it should overwrite the original values.
Additional info
Beta Was this translation helpful? Give feedback.
All reactions