Is there any way to access custom data stored in a customer session from a JS file ( without Ajax call ).
Here is the code for controller:
<?php
namespace Company\Vendor\Controller\Index;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Customer\Model\Session;
class Index extends Action
{
protected $_customerSession;
public function __construct(
Context $context,
Session $customerSession
) {
parent::__construct($context);
$this->_customerSession = $customerSession;
}
public function execute()
{
$this->_customerSession->setMyValue('yes');
}
}
To access the MyValue value, we can use $this->_customerSession->getMyValue();
How can I get the MyValue value in a JS file?