3

In my custom theme, I added custom template for which I am getting invalid template file error in system.log. My xml file loctaion:

app/design/frontend/{vendor}/{theme}/Magento_catalog/layout/catalog_product_view.xml

My template file location

app/design/frontend/{vendor}/{theme}/Magento_catalog/templates/product/view/size_guide.phtml

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:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.details">
<block class="Magento\Catalog\Block\Product\View\Description" name="size_guide" template="Magento_Catalog::product/view/size_guide.phtml" group="detailed_info">
<arguments>
    <argument name="title" translate="true" xsi:type="string">Size Guide</argument>
</arguments>
</block>
</referenceBlock>
<!-- this is code to add new tab end -->
</body>
</page>

size_guide.phtml

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('size_guide')->toHtml(); ?>

Magento looks for the template file in module-catalog and gives the error when not found. Why does Magento not pick up the template file from my theme?

1

place your size_guide.phtml in your module i.e {code}/{vendor}/{module}/view/frontend/templates/product/view/size_guide.phtml it worked for me.

  • i have placed the template file as app/code/Magento/Catalog/view/frontend/templates/product/view/size_guide.phtml. Still its not working? – azam Mar 22 '16 at 14:55
  • than check your xml file. i think you are not calling template file properly...otherwise share the files we will check. – Anand Ontigeri Mar 23 '16 at 3:45
  • i have given my xml file contents above, i am calling the template file as: Magento_Catalog::product/view/size_guide.phtml. – azam Mar 23 '16 at 6:41
  • remove Magento_Catalog and give your module name. – Anand Ontigeri Mar 23 '16 at 8:25
  • you mean removing Magento_Catalog from app/design/frontend/myvendor/mytheme/ and create new module there, placing my xml file like app/design/frontend/myvendor/mytheme/mymodule/layout/? if so then should i keep the template file as app/code/Magento/Catalog/view/frontend/templates/product/view/size_guide.phtml? – azam Mar 23 '16 at 8:36
1

This is probably because the name of the module is not is proper case.

When creating the folder structure,

app/design/frontend/{vendor}/{theme}/Magento_catalog/layout/catalog_product_view.xml

replace the Magento_catalog with Magento_Catalog. That will direct Magento to pick up the proper template.

0

Your size_,guide.phtml file is need to store in app/design/vendor/theme/frontend/Magento_Catalog/templates/size_guide.phtml

Because, you had used default module name Magento_Catalog that's why you can't store in app/code.

0

Since you are overriding the catalog_product_view.xml in your theme, you have to create the folders override/base inside your layout folder. Hence your layout file path should be like the following

app/design/frontend/{vendor}/{theme}/Magento_catalog/layout/override/base/catalog_product_view.xml

Now run the setup upgrade command and refresh. This has worked for me.

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.