0

I'm inside an observer

<event name="layout_load_before">
    <observer name="add_robot" instance="FranceTombale\Robot\Observer\NoindexfollowOnProduct" />
</event>

My goal is to alter the layout of some specific url

So inside the observer this is what I have :

use Magento\Framework\App\Response\RedirectInterface;

$redirectUrl = $this->redirect->getRedirectUrl();
$logger->info('Redirect url observer :'.$redirectUrl);
$linkCollection =$this->linkNoIndexCollection->getItems();
foreach ($linkCollection as $item) {
    $urlItem = $item->getData('url');
    if ($urlItem == $redirectUrl) { // .... the code logic updating the layout }
}

But this is not acting like I would like it act.

For example, if i'm on the page htpp://website/home and I try to go on the page http://website/myproduct then the value of $redirectUrl is htpp://website/home when what I would need for my logic to work is to get the value http://website/myproduct

Any ideas ?

1 Answer 1

0

I may did not get you'r problem properly but can you write this observer:

controller_action_predispatch_

And You can write logic accordingly this:

$this->eventManager->dispatch('controller_action_predispatch' . $request->getRouteName(), $eventParameters);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.