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
    Commented 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
    Commented Feb 20, 2019 at 7:50
  • have you checked this magento.stackexchange.com/questions/251924/…
    – fmsthird
    Commented 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
    Commented Feb 20, 2019 at 8:11
  • so your original is already like : $realPath = str_replace("\\", "/", $this->fileDriver->getRealPath($path)); ?
    – fmsthird
    Commented 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
    Commented 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
    Commented 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Ǝ
    Commented 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
    Commented 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
    Commented 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
    Commented Feb 21, 2019 at 3:25
  • yes tried that also but not working .
    – Flutterer
    Commented Feb 21, 2019 at 7:22

Your Answer

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

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