I have created events.xml in app/code/Demo/Mymodule/etc/frontend:
<?xml version="1.0">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="layout_load_before">
<observer name="add_layout_handles" instance="Demo\Mymodule\Observer\AddHandles" />
</event>
</config>
And AddHandles.php in app/code/Demo/Mymodule/Observer:
<?php
namespace Demo\Mymodule\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Customer\Model\Session as CustomerSession;
class AddHandles implements ObserverInterface
{
protected $customerSession;
public function __construct(CustomerSession $customerSession)
{
$this->customerSession = $customerSession;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$layout = $observer->getEvent()->getLayout();
if (!$this->customerSession->isLoggedIn())
{
$layout->getUpdate()->addHandle('customer_logged_out');
}
}
}
On running php bin/magento setup:di:compile
getting this error: arse error: syntax error, unexpected 'public' (T_STRING
), expecting function (T_FUNCTION) or const (T_CONST)
Can anyone help me?
I am using Magento 2.2.4 version.