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!
2 Answers 2
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
 
 
 
 Rakesh Donga 
 
 5,4442 gold badges26 silver badges58 bronze badges
 
 - 
 Can you please guide me how to edit this code for my module and attribute? Thanksvladboing– vladboing2019年02月04日 07:27:59 +00:00Commented 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 tocustom_attributeRakesh Donga– Rakesh Donga2019年02月04日 07:30:11 +00:00Commented 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:2191vladboing– vladboing2019年02月04日 07:46:39 +00:00Commented Feb 4, 2019 at 7:46
- 
 give me your custom attribute nameRakesh Donga– Rakesh Donga2019年02月04日 08:03:46 +00:00Commented Feb 4, 2019 at 8:03
- 
 The name is: product_vendorvladboing– vladboing2019年02月04日 08:06:15 +00:00Commented Feb 4, 2019 at 8:06
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
 
 
 
 Dhairya Shah 
 
 8326 silver badges13 bronze badges
 
 Explore related questions
See similar questions with these tags.
default