I am Creating a simple layout block and template, but it is giving error

Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Test_Module::stock_left.phtml' in module: 'Test_Module' block's name: 'productleft'

layout catalog_product_view.xml

<?xml version="1.0"?>
<page layout = "1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <referenceContainer name="product.info.main">
            <block class="Test\Module\Block\StockLeft" name="productleft" template="Test_Module::stock_left.phtml"/>

Block StockLeft.php


namespace Test\Module\Block;

use Magento\Framework\view\Element\Template;

class StockLeft extends Template{


Template : stock_left.phtml

/**@var \Test\Module\Block\stockleft $blocks */


<h1>hello world</h1>

Thanks in advance.

  • Can you please let me know your template's file path ? – Kishan Savaliya Nov 11 '19 at 11:10
  • @KishanSavaliya Template path is vendorname/modulename/view/frontend/template/stock_left.phtml – vinaysirige Nov 11 '19 at 11:15

You need to create your template file inside templates directory not template like

in Module :


or in Theme :


Create your template file here in your module


Hope this will help you!

| improve this answer | |
  • Thanks @kishan savaliya it works – vinaysirige Nov 11 '19 at 11:24
  • Can you please accept my answer ? @vinaysirige – Kishan Savaliya Nov 11 '19 at 12:10
  • thanks it worked – vinaysirige Nov 11 '19 at 12:16
  • That will helpful to me :) – Kishan Savaliya Nov 11 '19 at 12:18
  • I accepted the Answer – vinaysirige Nov 11 '19 at 12:49

In Block you have a typo.

use this: \Magento\Framework\View\Element\Template

Let me know if this helps


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.