Hello,
right now we can attach an handler to the yii\web\View::EVENT_BEFORE_RENDER
event but this is triggered every time a view is requested ("regular" view, partial or layout).
I think it might be also useful to have a similar one that is triggered when using the render method from a controller (\yii\base\Controller->render($view, $params = [])
)
In this way we have an event that is usually triggered once per page load that is in between beforeAction and afterAction but it is actually triggered inside the action just before rendering the page.
A practical example: you load some content from the database in your controller through your model and you want to set your current page title in the view / theme. You also then want to have a method that automatically takes your title and populate some open graph or twitter cards tags. The event will then fire before rendering the page allowing the event handler to populate the meta tags based on the information set in the action before calling the render method.
Let me know if it makes sense, thanks :)
+1
My usecase is dynamic meta information (title, description etc.) for one pages and static for another ones. They both use the same layout. I can't get some clever workarounds - I need to add some logic before $this->render() in every public method of controller.
is there any behavior or component that might use that feature? otherwise it might be simpler to overwrite the render()
method.
public function render($view, $params)
{
// before render
return parent::render($view, $params);
}
Most helpful comment
is there any behavior or component that might use that feature? otherwise it might be simpler to overwrite the
render()
method.