cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2 event name for home page and all front-end pages

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

2 REPLIES 2

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.

Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now

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;
}

 

Suman Kar(suman.jis@gmail.com) Magento Certified Developer Plus Skype: sumanphptech Problem solved? Please give 'Kudos' and accept 'Answer as Solution'.