---
title: "Call phtml File From Helper In Magento 2"
url: "https://dolphinwebsolution.com/call-phtml-file-from-helper-in-magento-2"
date: "2021-08-08T11:37:42+05:30"
modified: "2023-08-24T09:21:48+05:30"
author:
  name: "Mahesh Makwana"
categories:
  - "Magento"
word_count: 215
reading_time: "2 min read"
summary: "We can call phtml file form many ways. Here we will show you how to call phtml file From Helper. Helper functions are accessible for all areas of Magento.

Add below code in Data.php at app/code/..."
description: "We can call phtml file form many ways. Here we will show you how to call phtml file From Helper. Helper functions are accessible for all areas of Magento."
keywords: "Call phtml File,Call phtml File From Helper,phtml File From Helper, Magento"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How Much Does Magento Development Cost in 2026?"
    url: "https://dolphinwebsolution.com/blog/magento-development-cost/"
  - title: "How to Set Price Format using JavaScript in Magento 2"
    url: "https://dolphinwebsolution.com/set-price-format-using-javascript-in-magento-2"
  - title: "How to Add Custom Block to Order View Information in Magento"
    url: "https://dolphinwebsolution.com/add-custom-block-to-order-view-information-in-magento"
---

# Call phtml File From Helper In Magento 2

_Published: August 8, 2021_  
_Author: Mahesh Makwana_  

![](https://dolphinwebsolution.com/wp-content/uploads/2023/02/blog-post-3-1024x538.jpg)

> We can call phtml file form many ways. Here we will show you how to call phtml file From Helper. Helper functions are accessible for all areas of Magento. Add below code in Data.php at app/code/VendoreName/ModuleName/Helper

We can call phtml file form many ways. Here we will show you how to call phtml file From Helper. Helper functions are accessible for all areas of Magento.

**Add below code in Data.php at app/code/VendoreName/ModuleName/Helper**

```
<?php

namespace VendoreName\ModuleName\Helper;

use Magento\Framework\App\Helper\AbstractHelper;

class Data extends AbstractHelper
{
    protected $layoutFactory;

    public function __construct(
        .....
        \Magento\Framework\View\LayoutFactory $layoutFactory,
        .....
    ) {
        .....
        $this->layoutFactory = $layoutFactory;
        .....
    }

    public function getPHtmlFile()
    {
        $layout = $this->layoutFactory->create();
        $blockOption = $layout->createBlock("Your Block path")->setTemplate('VendoreName_ModuleName::YourphtmlfileName.phtml')
        return $blockOption->toHtml();
    }
}
```

Here block file and phtml file must be in same area. **\\Magento\\Framework\\View\\Element\\Template** extends class are **frontend** class which phtml file path is **app/code/VendoreName/ModuleName/view/frontend/templates** and **\\Magento\\Backend\\Block\\Template** extends class are **Adminhtml** class which [phtml file](https://magento.stackexchange.com/questions/116389/how-to-override-phtml-files-in-magento-2) path is **app/code/VendoreName/ModuleName/view/adminhtml/templates**. We can call **getPHtmlFile()** function are call everywhere you want to call.

**Note: If your phtml file does not use any block then you must pass the default class which is extended.**

**Frontend : Magento\\Framework\\View\\Element\\Template**
**Adminhtml : Magento\\Backend\\Block\\Template**

I hope this helps you. For any doubts regarding this topic, please write your doubts in the comments section.


---

_View the original post at: [https://dolphinwebsolution.com/call-phtml-file-from-helper-in-magento-2](https://dolphinwebsolution.com/call-phtml-file-from-helper-in-magento-2)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-26 06:54:13 UTC_  
