0

I've been trying to add phtml to my custom theme but it doesn't show for example

<block class="Magento\Catalog\Block\Product\View" name="product_view_custom_block" before="-" template="Magento_Catalog::product/view/custom_block.phtml"/>

path for xml is <theme_name>\<theme>\Magento_Catalog\layout\catalog_category_view.xml

path is <theme_name>\<theme>\Magento_Catalog\product\view\custom_block.phtml

the template="" what should I put inside the double quotes? Did I do this right?

I'm using Magento 2.4.4

2 Answers 2

0

Please try to add it like this.

<block class="Magento\Framework\View\Element\Template" name="category.custom.block" template="Magento_Catalog::product/view/custom_block.phtml"/>
0

Try below code.

app/code/theme_name/theme/Magento_Catalog/layout/catalog_category_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Magento_Catalog::product/view/custom_block.phtml" />
        </referenceContainer>
    </body>
</page>

Now create custom_block.phtml and place your code

app/code/theme_name/theme/Magento_Catalog/product/view/custom_block.phtml

<?php

echo "Called custom phtml file";

?>

If any query let me know.

THANKS.

2
  • I'm getting the error ----- 1 exception(s): Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Magento_Catalog::product/view/custom_block.phtml' in module: '' block's name: 'custom.block' Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Magento_Catalog::product/view/custom_block.phtml' in module: '' block's name: 'custom.block' <pre>#1 Magento\Framework\View\Element\Template->_toHtml() called at [vendor\magento\framework\View\Element\AbstractBlock.php:1095] Commented Aug 15, 2022 at 19:18
  • please share your full phtml path. Commented Aug 16, 2022 at 3:40

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.