I have created one custom attribute through code, in admin product edit page,but i wolud like to display that value in product detail page,
How to get the custom attribute collection in product detail page magento2.
i have tried with the below code but it is giving an error:
$_attributeValue = $_product->getResource()->getAttribute ($_code)->getFrontend()->getValue($_product);
Fatal error: Uncaught Error: Call to a member function getFrontend() on boolean in 
Help me thankful
Thanks
 asked Mar 28, 2019 at 6:58
 
 
 
 shivashankar m 
 
 2,5064 gold badges29 silver badges53 bronze badges
 
 - 
 1try this $_product->getData('your_attribute');Rakesh Donga– Rakesh Donga2019年03月28日 07:01:58 +00:00Commented Mar 28, 2019 at 7:01
 - 
 1Make sure the attribute exist for the product you're getting, guess that would be the issue @shiivashankarmPrathap Gunasekaran– Prathap Gunasekaran2019年03月28日 07:04:26 +00:00Commented Mar 28, 2019 at 7:04
 - 
 Thanks @PrathapGunasekaran issue with value only now the value is getting.shivashankar m– shivashankar m2019年03月28日 07:16:40 +00:00Commented Mar 28, 2019 at 7:16
 
1 Answer 1
$_attributeValue = $_product->getCustomAttribute($_code)
Will give the custom attribute value if $_product is repository object.
If it is a model object you can refer to @Rakesh Donga's comment
 answered Mar 28, 2019 at 7:02
 
 
 
 Bhargava Rama 
 
 1931 silver badge9 bronze badges
 
 - 
 If your issue is solved. Please accept this as answer. @shiivashankarmBhargava Rama– Bhargava Rama2019年03月28日 07:19:40 +00:00Commented Mar 28, 2019 at 7:19
 - 
 Hi @bhargav, iam calling custom phtml file to product view page like the code: <referenceContainer name="product.info.form.content" > <block class="Vendor\Module\Block\Product\View\test" name="reward_frontend_msg" template="Vendor_Module::product/view/test.phtml" before="product.info.addtocart"/> </referenceContainer>shivashankar m– shivashankar m2019年03月28日 07:36:25 +00:00Commented Mar 28, 2019 at 7:36
 - 
 but it is calling for newly created products previosly existing products it is not displayingshivashankar m– shivashankar m2019年03月28日 07:37:10 +00:00Commented Mar 28, 2019 at 7:37
 - 
 Can you share the Vendor\Module\Block\Product\View\test block code?Bhargava Rama– Bhargava Rama2019年03月28日 08:08:45 +00:00Commented Mar 28, 2019 at 8:08
 - 
 Please find the link to block code: magento.stackexchange.com/questions/267766/…shivashankar m– shivashankar m2019年03月28日 08:21:07 +00:00Commented Mar 28, 2019 at 8:21
 
default