- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Magento2 event name for home page and all front-end pages
Hi,
I want to run my method in observer on the home page and all front-end pages of the website.
I am looking for event name which will trigger on the home page and all pages in the front-end of the website.
For example: controller_action_predispatch
Any idea?
Best Regards
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento2 event name for home page and all front-end pages
Hello @zohaibfk_khan
There are no.of events that can help you to call frontend page load.
Event name: controller_action_layout_render_before
File: vendor/magento/framework/App/View.php
Event name: controller_front_send_response_before
File: vendor/magento/framework/App/Http.php
Event name: controller_action_layout_render_before_
File: vendor/magento/framework/App/View.php
You can use any one from the above.
Still if you have any question. Please let us know your full requirement so we can help you out.
200+ Premium Magento 2 Extensions Need help? Hire Magento Developer
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento2 event name for home page and all front-end pages
Check the class vendor/magento/framework/App/Http.php
Function name : lunch()
$this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
Check the class vendor/magento/framework/App/Action/Action.php
Function Name : dispatch()
public function dispatch(RequestInterface $request)
{
$this->_request = $request;
$profilerKey = 'CONTROLLER_ACTION:' . $request->getFullActionName();
$eventParameters = ['controller_action' => $this, 'request' => $request];
$this->_eventManager->dispatch('controller_action_predispatch', $eventParameters);
$this->_eventManager->dispatch('controller_action_predispatch_' . $request->getRouteName(), $eventParameters);
$this->_eventManager->dispatch(
'controller_action_predispatch_' . $request->getFullActionName(),
$eventParameters
);
\Magento\Framework\Profiler::start($profilerKey);
$result = null;
if ($request->isDispatched() && !$this->_actionFlag->get('', self::FLAG_NO_DISPATCH)) {
\Magento\Framework\Profiler::start('action_body');
$result = $this->execute();
\Magento\Framework\Profiler::start('postdispatch');
if (!$this->_actionFlag->get('', self::FLAG_NO_POST_DISPATCH)) {
$this->_eventManager->dispatch(
'controller_action_postdispatch_' . $request->getFullActionName(),
$eventParameters
);
$this->_eventManager->dispatch(
'controller_action_postdispatch_' . $request->getRouteName(),
$eventParameters
);
$this->_eventManager->dispatch('controller_action_postdispatch', $eventParameters);
}
\Magento\Framework\Profiler::stop('postdispatch');
\Magento\Framework\Profiler::stop('action_body');
}
\Magento\Framework\Profiler::stop($profilerKey);
return $result ?: $this->_response;
}