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, 2019 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
    – Flutterer
    Feb 20, 2019 at 7:50
  • have you checked this magento.stackexchange.com/questions/251924/…
    – fmsthird
    Feb 20, 2019 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 ...
    – Flutterer
    Feb 20, 2019 at 8:11
  • so your original is already like : $realPath = str_replace("\\", "/", $this->fileDriver->getRealPath($path)); ?
    – fmsthird
    Feb 20, 2019 at 8:15

2 Answers 2


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 ...
    – Flutterer
    Feb 20, 2019 at 19:50
  • <block class="Sam\Options\Block\Check" name="header.right.custom.area" template="Sam_Options::after_nav_banner.phtml" after="navigation.sections">
    – Flutterer
    Feb 20, 2019 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, 2019 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 :)
    – Flutterer
    Feb 22, 2019 at 19:30

Put your template file inside this path:


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
    – Flutterer
    Feb 21, 2019 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">
    – fmsthird
    Feb 21, 2019 at 3:25
  • yes tried that also but not working .
    – Flutterer
    Feb 21, 2019 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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