I need to get the value of a custom attribute on the product page, as I want to display different sizechart per attribute. For this reason, I have created the following .phtml to get the value of the attribute:
File: /app/design/frontend/Mgs/claue/Magento_Catalog/templates/product/view/sizechart.phtml
<?php
$_product = $block->getProduct();
$attribute = $_product->getResource()->getAttribute('sizechart2');
?>
And I have called this file from:
File: /app/design/frontend/Mgs/claue/Magento_Catalog/layout/catalog_product_view.xml
<referenceContainer name="product.info.main">
<block class="Magento\Framework\View\Element\Template" name="custom.text" template="Magento_Catalog::product/view/sizechart.phtml" after="product.info.price"/>
</referenceContainer>
But when I go to product page show the following error:
Fatal error: Uncaught Error: Call to a member function getResource() on null
What is the problem? :(
Thanksss