In today’s Magento blog, I am going to explain Emulating Areas in Magento 2.
The simple meaning of emulating is imitating. In Magento 2 while working with frontend and backend if you want to simulate one area with another, at that time the concept of the emulating area is used.
For instance, here I have explained how to get a frontend website logo URL in the admin area using emulation in Magento 2. When there is a need to get the website logo URL in the Magento admin area at that time if we apply the code of the frontend area, we do not get the logo URL. In this situation, we need to use emulating areas to get the frontend logo URL in the Magento Admin area.
Use the below code for Emulating Areas in Magento 2.
How to Emulate Area in Magento 2:
You can do it in any file but here we create a controller to achieve this.
Step 1: Add menu.xml in the following path
app/code/Vendor/Extension/etc/adminhtml/menu.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Menu/etc/menu.xsd">
<menu>
<add id="Vendor_Extension::menu_root" title="Vendor Extensions" module="Vendor_Extension" sortOrder="50" resource="Vendor_Extension::getlogourl"/>
<add id="Vendor_Extension::getlogourl" title="Get Logo URL" module="Vendor_Extension" sortOrder="10" parent="Vendor_Extension::menu_root" action="extension/getlogourl/index" resource="Vendor_Extension::getlogourl"/>
</menu>
</config>Step 2: Add routes.xml in the following path
app/code/Vendor/Extension/etc/adminhtml/routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="extension" frontName="extension">
<module name="Vendor_Extension" />
</route>
</router>
</config>Step 3: Add Index.php in the following path
app/code/Vendor/Extension/Controller/Adminhtml/Getlogourl/Index.php
<?php
namespace Vendor\Extension\Controller\Adminhtml\Getlogourl;
use Magento\Backend\App\Action;
use Magento\Theme\Block\Html\Header\Logo;
use Magento\Store\Model\App\Emulation;
use Magento\Framework\Controller\ResultFactory;
class Index extends Action
{
protected $logo;
protected $emulation;
public function __construct(
Action\Context $context,
Logo $logo,
Emulation $emulation
) {
parent::__construct($context);
$this->logo = $logo;
$this->emulation = $emulation;
}
public function execute()
{
$storeId = 1;
$logoUrl = '';
try {
$this->emulation->startEnvironmentEmulation(
$storeId,
\Magento\Framework\App\Area::AREA_FRONTEND,
true
);
$logoUrl = $this->logo->getLogoSrc();
$this->emulation->stopEnvironmentEmulation();
} catch (\Exception $e) {
$logoUrl = "Error: " . $e->getMessage();
}
$result = $this->resultFactory->create(ResultFactory::TYPE_RAW);
$result->setContents($logoUrl);
return $result;
}
}Conclusion:
This way you can Emulate Area in Magento 2 to get the logo URL in the admin panel. Alternatively, Get Logo URL, Alt Text, Logo Size in Magento 2 to increase brand awareness.
If you have any doubts regarding this, you can inform me via the comment box. I will be happy to solve it for you. Spread the article amongst your friends and remain updated for more such Magento 2 solutions.
Happy Coding!
FAQ
What does “emulating area” mean in Magento 2?
In Magento 2, different parts of the system operate in different areas such as frontend, adminhtml, crontab, or webapi_rest. Area emulation allows you to temporarily run code in a specific area context so you can access layout, templates, translations, and configurations belonging to that area.
Is it mandatory to pass the store ID while emulating a frontend area?
Yes. A store ID ensures that the correct store view configuration, locale, currency, and theme are applied during emulation.






