0

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">
 <body>
 <referenceContainer name="product.info.main">
 <block class="Test\Module\Block\StockLeft" name="productleft" template="Test_Module::stock_left.phtml"/>
 </referenceContainer>
 </body>
</page>

Block StockLeft.php

<?php 
namespace Test\Module\Block;
use Magento\Framework\view\Element\Template;
class StockLeft extends Template{
}

Template : stock_left.phtml

<?php
/**@var \Test\Module\Block\stockleft $blocks */
?>
<h1>hello world</h1>

Thanks in advance.

Kishan Savaliya
7,8451 gold badge14 silver badges29 bronze badges
asked Nov 11, 2019 at 11:07
2
  • Can you please let me know your template's file path ? Commented Nov 11, 2019 at 11:10
  • @KishanSavaliya Template path is vendorname/modulename/view/frontend/template/stock_left.phtml Commented Nov 11, 2019 at 11:15

2 Answers 2

2

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

in Module :

app/code/Vendor/Module/view/frontend/templates/template.phtml

or in Theme :

app/design/frontend/Vendor/Theme/Magento_Theme/templates/template.phtml

Create your template file here in your module

app/code/Test/Module/view/frontend/templates/stock_left.phtml

Hope this will help you!

answered Nov 11, 2019 at 11:18
5
  • Thanks @kishan savaliya it works Commented Nov 11, 2019 at 11:24
  • Can you please accept my answer ? @vinaysirige Commented Nov 11, 2019 at 12:10
  • That will helpful to me :) Commented Nov 11, 2019 at 12:18
  • I accepted the Answer Commented Nov 11, 2019 at 12:49
  • Thanks Buddy. :) Commented Nov 11, 2019 at 12:50
0

In Block you have a typo.

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

Let me know if this helps

Thnx

answered Nov 11, 2019 at 11:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.