---
title: "How to Set a Theme on a Specific Page in Magento 2?"
url: "https://magecomp.com/blog/set-theme-on-specific-page-magento-2/"
date: "2023-08-25T12:39:07+00:00"
modified: "2025-02-13T05:34:01+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 819
reading_time: "5 min read"
summary: "Hello Magento Friends,"
description: "Personalize the user experience by setting theme for specific page in Magento 2. Check out the step by step guide."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Delete a Specified Order Status Comment in Magento 2?"
    url: "https://magecomp.com/blog/delete-specified-order-status-comment-magento-2/"
  - title: "How to Set and Get Cookie in Magento 2?"
    url: "https://magecomp.com/blog/set-and-get-cookie-magento-2/"
  - title: "A Complete Guide on Keeping Magento 2 Store Maintained/Up to Date"
    url: "https://magecomp.com/blog/complete-guide-on-keeping-magento-2-store-maintained/"
---

# How to Set a Theme on a Specific Page in Magento 2?

_Published: August 25, 2023_  
_Author: Dhiren Vasoya_  

![How to Set a Theme on a Specific Page in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/08/How-to-Set-a-Theme-on-a-Specific-Page-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

In this blog, I will explain the steps to Set a Theme on a Specific Page in Magento 2.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-2.webp)](https://magecomp.com/magento-performance-optimization.html)

Magento 2 allows you to set a global theme for your entire store. But there might be cases where you want to apply a different theme to a specific page. This could be for promotional campaigns, seasonal changes, or any other reason.
Let’s go through the process of setting a theme on a specific page in Magento 2.
## Steps to Set a Theme on a Specific Page in Magento 2:
**Step 1:** Create a **routes.xml** file in the path given below
**{{magento_root}}\app\code\Vendor\Extension\etc\frontend\routes.xml**

Then add the code as follows.
```
<?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="standard">
        <route id="frontroute" frontName="frontroute">
            <module name="Vendor_Extension"/>
        </route>
    </router>
</config>
```

**Step 2:** Create a **controller file** in the following path
**{{magento_root}}\app\code\Vendor\Extension\Controller\Index\Index.php**

Then add the code as given below.
```
<?php

namespace VendorExtensionControllerIndex;

use MagentoFrameworkAppActionHttpGetActionInterface;
use MagentoFrameworkControllerResultInterface;
use MagentoFrameworkViewResultPageFactory;

class Index implements HttpGetActionInterface
{
    /**
     * @var PageFactory
     */
    protected $resultPageFactory;

    /**
     * Constructor
     *
     * @param PageFactory $resultPageFactory
     */
    public function __construct(PageFactory $resultPageFactory)
    {
        $this->resultPageFactory = $resultPageFactory;
    }

    /**
     * Execute view action
     *
     * @return ResultInterface
     */
    public function execute()
    {
        return $this->resultPageFactory->create();
    }
}
```

**Step 3:** Create a **layout file** at the below-mentioned path
**{{magento_root}}\app\code\Vendor\Extension\view\frontend\layout\frontroute_index_index.xml**

Add the following code-snippet
```
<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block name="index.index" class="VendorExtensionBlockIndexIndex" template="Vendor_Extension::index/index.phtml"/>
        </referenceContainer>
    </body>
</page>
```

**Step 4:** Create a **template file** at the path mentioned below
**{{magento_root}}\app\code\Vendor\Extension\view\frontend\templates\index\index.phtml**

Now, add the code as given below.
```
<?php
/**
 *
 * @var $block VendorExtensionBlockIndexIndex
 */
?>

<h2>This page is Magento Black theme.</h2>
```

[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-6.webp)](https://magecomp.com/services/hyva-theme-development/)

**Step 5:** Create a **Block file** at the below path
**{{magento_root}}\app\code\Vendor\Extension\Block\Index\Index.php**

Then add the below-mentioned piece of code.
```
<?php

namespace VendorExtensionBlockIndex;

class Index extends MagentoFrameworkViewElementTemplate
{
    /**
     * Constructor
     *
     * @param MagentoFrameworkViewElementTemplateContext  $context
     * @param array $data
     */
    public function __construct(
        MagentoFrameworkViewElementTemplateContext $context,
        array $data = []
    ) {
        parent::__construct($context, $data);
    }
}
```

**Step 6:** Create an **events file** at the following path
**{{magento_root}}\app\code\Vendor\Extension\etc\events.xml**

Then, include the code as follows.
```
<?xml version="1.0" encoding="UTF-8"?>
<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="observer_name" instance="VendorExtensionObserverSetThemePage"/>
    </event>
</config>
```

**Step 7:** Create an **observer class file** at the following path
**{{magento_root}}\app\code\Vendor\Extension\Observer\SetThemePage.php**

And the below-mentioned code
```
<?php

namespace VendorExtensionObserver;

use MagentoFrameworkAppRequestHttp;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkViewDesignInterface;

class SetThemePage implements ObserverInterface
{
    /** @var Http */
    private Http $request;

    /** @var DesignInterface  */
    private DesignInterface $design;

    /**
     * @param Http $request
     * @param DesignInterface $design
     */
    public function __construct(
        Http $request,
        DesignInterface $design
    ) {
        $this->request = $request;
        $this->design = $design;
    }

    /**
     * @param Observer $observer
     */
    public function execute(Observer $observer): void
    {
        $pathInfo = $this->request->getPathInfo();
        if (substr($pathInfo, 0, 8) === '/frontroute') {
            $this->design->setDesignTheme('Magento/blank');
        }
    }
}
```

**Step 8:** Finally, run the below commands.
```
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento setup:di:compile
php bin/magento cache:flush
```

## Conclusion:
Setting a theme on a specific page in Magento 2 is a powerful way to create unique experiences for your customers. By following the steps outlined in this blog post, you can effectively apply different themes to specific pages and enhance the visual appeal and functionality of your Magento 2 store.
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-4.webp)](https://magecomp.com/services/hire-magento-programmer/)

You may also like to check out below blogs –
> [**How to Apply Admin Theme in Magento 2?**](https://magecomp.com/blog/apply-admin-theme-magento-2/)
>
> [**How to Create Child Theme in Magento 2**](https://magecomp.com/blog/create-child-theme-magento-2/)
>
> [**Easy Method to Apply The Default Theme In Magento 2**](https://magecomp.com/blog/apply-default-theme-magento-2/)
>
> [**How to Change Theme In Magento 2**](https://magecomp.com/blog/change-theme-in-magento-2/)

If you face any difficulty or errors while executing the above steps, kindly let me know through the comment box, and I will quickly help you out to get rid of the error. Share the tutorial to set a theme for a specific page in Magento 2 with your friends, and stay in touch with us.
**Happy Coding!**

</body>


---

_View the original post at: [https://magecomp.com/blog/set-theme-on-specific-page-magento-2/](https://magecomp.com/blog/set-theme-on-specific-page-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-07-18 05:39:29 UTC_  
