Issue
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'TT::calculator.phtml' in module: 'Magento_Catalog' block's name: 'calculator.tab'
Layout Location:
app/code/TT/Calculator/view/frontend/layout/catalog_product_view.xml
<?xml version="1.0"?>
<page 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" name="calculator.tab" template="TT::calculator.phtml" group="detailed_info">
<arguments>
<argument translate="true" name="title" xsi:type="string">Calculator</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Template Location:
app/code/TT/Calculator/view/frontend/templates/calculator.phtml
Questions
- I've seen some solutions where the *.phtml file is saved in app/design but I'm trying to get this to work in app/code. What have I missed?
- Also, does this "extend" catalog_product_view.xml or replace it?
-
You have to change to TT_Calculator::calculator.phtml.Nero Phung– Nero Phung2017年11月27日 15:56:27 +00:00Commented Nov 27, 2017 at 15:56
-
I typo'd after fixing, making me think it didn't work. Thanks all!Craig– Craig2017年11月27日 16:37:00 +00:00Commented Nov 27, 2017 at 16:37
3 Answers 3
1.You have to change the code to TT_Calculator::calculator.phtml:
<?xml version="1.0"?>
<page 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" name="calculator.tab" template="TT_Calculator::calculator.phtml" group="detailed_info">
<arguments>
<argument translate="true" name="title" xsi:type="string">Calculator</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
2.Magento will check all the layout (XML file) in all the modules and merge them, not extend.
Your template file location should be TT_Calculator::calculator.phtml
<block class="Magento\Catalog\Block\Product\View" name="calculator.tab" template="TT_Calculator::calculator.phtml" group="detailed_info">
<arguments>
<argument translate="true" name="title" xsi:type="string">Calculator</argument>
</arguments>
</block>
I have resolved this issue now. The problem was the allow symlink of the system config:
php bin/magento config:set dev/template/allow_symlink 1 --lock-env