I want to create a Magento\Catalog\Block\Product\View block in a custom controller action (which will be used for an AJAX call later on). However I am getting the following error when creating the block (and setting the template):

Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Vendor_Module::product.phtml' in module: 'Magento_Catalog' block's name: 'product\view_0'



namespace Vendor\Module\Controller\Product;

class View extends \Magento\Catalog\Controller\Product
    protected $layoutFactory;
    protected $resultFactory;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\LayoutFactory $layoutFactory,
        \Magento\Framework\Controller\Result\RawFactory $resultFactory
    ) {
        $this->layoutFactory = $layoutFactory;
        $this->resultFactory = $resultFactory;

    public function execute()
        $block = $this->layoutFactory->create()

        $result = $this->resultFactory->create();

        return $result;


<p>Hello World!</p>


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="foo" frontName="foo">
            <module name="Vendor_Module" />

I can't find the mistake. The definition of the template (Vendor_Module::product.html) plus the template's location should be correct. I also tried putting the template directly in app/code/Vendor/Module/view - but that did not change anything.

What could be the problem here?

2 Answers 2


Simple solution: I forgot the templates subfolder in my template's path. So instead of


it should of course be



Try to add the template in this tree directory app/code/Vendor/Module/view/frontend/templates/product/view/product.phtml

  • No, that did not work. That wouldn't make any sense anyway, since the template I am setting for the block is Vendor_Module::product.phtml, not Vendor_Module::product/view/product.phtml.
    – fritzmg
    Feb 14, 2018 at 17:51

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.