1

I am seeing invalid template file error

Invalid template file: 'Sam_Options::after_nav_banner.phtml' in module: '' block's name: 'header.right.custom.area'

I have tried doing view in small letters and View in camel case letters but nothing works , I have tried template and templates both but no success .

.phtml file is in Sam/Options/view/frontend/templates/after_nav_banner.phtml

I have cleared cache delete cache folders tried everything.
What can be the issue?

Block code is this:

<block class="Magento\Framework\View\Element\Template" name="header.right.custom.area" template="Sam_Options::after_nav_banner.phtml" after="navigation.sections">

template file C:\xampp\htdocs\learnm2\app\code\Sam\Options\view\frontend\templates\after_nav_banner.phtml xml file C:\xampp\htdocs\learnm2\app\code\Sam\Options\view\frontend\layout\default.xml

  • Check the module Sam_Options enable or Not? – Amit Bera Feb 20 at 7:48
  • @AmitBera it is showing error on homepage i think it means module is enabled ? but as per you saying i have checked it yes it is enabled – samair ali Feb 20 at 7:50
  • have you checked this magento.stackexchange.com/questions/251924/… – magefms Feb 20 at 8:00
  • @magefms i have tried it ... in the core file validator.php if we change $realPath = str_replace("\\", "/", $this->fileDriver->getRealPath($path)); this line to $realPath = str_replace("\", "/", $this->fileDriver->getRealPath($path)); its shows error and if i change this line to $realPath = str_replace("\\", "\", $this->fileDriver->getRealPath($path)); it shows error ... – samair ali Feb 20 at 8:11
  • so your original is already like : $realPath = str_replace("\\", "/", $this->fileDriver->getRealPath($path)); ? – magefms Feb 20 at 8:15
0

Try this :

<block class="Sam\Options\Block\YourBlockNameHere" name="header.right.custom.area" template="Sam_Options::after_nav_banner.phtml" after="navigation.sections">
  • still the same issue ... – samair ali Feb 20 at 19:50
  • <block class="Sam\Options\Block\Check" name="header.right.custom.area" template="Sam_Options::after_nav_banner.phtml" after="navigation.sections"> – samair ali Feb 20 at 19:50
  • Do some echo <?php echo "Hello"; ?> in after_nav_banner.phtml then add this : <?php echo $this->getLayout()->createBlock("Sam\Options\Block\Check")->setTemplate("Sam_Options::after_nav_banner.phtml")->toHtml();?> in another phtml and tell me if you that echo – PЯINCƏ Feb 21 at 8:43
  • I have tried echo thing but didnt work ... i have added simple h1 tag with text but not working ... i have switched to ubuntu lets see maybe things will work smooth now but thanks for the answers :) – samair ali Feb 22 at 19:30
0

Put your template file inside this path:

C:\xampp\htdocs\learnm2\app\code\Sam\Options\view\frontend\templates\banner\after_nav_banner.phtml

Call it in your block like this:

<block class="Magento\Framework\View\Element\Template" name="header.right.custom.area" template="Sam_Options::banner/after_nav_banner.phtml" after="navigation.sections">

  • I have tried the exactly same way ... 100% same way to solve this issue but not fixed either – samair ali Feb 21 at 1:38
  • have you tried this one <block class="Magento\Framework\View\Element\Template" name="header.right.custom.area" template="after_nav_banner.phtml" after="navigation.sections"> – magefms Feb 21 at 3:25
  • yes tried that also but not working . – samair ali Feb 21 at 7:22

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.