0

I have created a custom module, which creating an product attribute, now I need to display this attribute on the frontend, right under product SKU enter image description here

How I can I do this? Thanks everyone!

asked Feb 3, 2019 at 20:36

2 Answers 2

1

create a layout file in your extension

NameSpace/ModuleName/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>
 <referenceContainer name="product.info.main">
 <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.product_vendor"
 template="Magento_Catalog::product/view/attribute.phtml" after="product.info.sku">
 <arguments>
 <argument name="at_call" xsi:type="string">getProductVendor</argument>
 <argument name="at_code" xsi:type="string">product_vendor</argument>
 <argument name="css_class" xsi:type="string">product_vendor</argument>
 <argument name="at_label" xsi:type="string">default</argument>
 <argument name="add_attribute" xsi:type="string">itemprop="product_vendor"</argument>
 </arguments>
 </block>
 </referenceContainer>
 </body>
answered Feb 4, 2019 at 5:21
6
  • Can you please guide me how to edit this code for my module and attribute? Thanks Commented Feb 4, 2019 at 7:27
  • you can create above file in your custom theme after add above code and your custom attribute name replace to custom_attribute Commented Feb 4, 2019 at 7:30
  • edited, but now getting this error: Uncaught ArgumentCountError: Too few arguments to function Magento\Catalog\Model\Product\Interceptor::getCustomAttribute(), 0 passed in /var/www/html/magento2/vendor/magento/module-catalog/view/frontend/templates/product/view/attribute.phtml on line 37 and exactly 1 expected in /var/www/html/magento2/generated/code/Magento/Catalog/Model/Product/Interceptor.php:2191 Commented Feb 4, 2019 at 7:46
  • give me your custom attribute name Commented Feb 4, 2019 at 8:03
  • The name is: product_vendor Commented Feb 4, 2019 at 8:06
4

Create a catalog_product_view.xml

<referenceContainer name="product.info.stock.sku">
 <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.cutom.attribute" template="Magento_Catalog::product/view/attribute.phtml" after="product.info.sku">
 <arguments>
 <argument name="at_call" xsi:type="string">getYourAttribute</argument>
 <argument name="at_code" xsi:type="string">your_attribute_code</argument>
 <argument name="css_class" xsi:type="string">custom_css_class</argument>
 <argument name="at_label" xsi:type="string">default</argument>
 <argument name="add_attribute" xsi:type="string">itemprop="your_attribute_code"</argument>
 </arguments>
 </block>
</referenceContainer>
answered Feb 4, 2019 at 5:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.